How To Save Data Into Another Data Collection in onClick?

I have a two (2) data collection and I want to save some data form d a taCollection1 to d a taCollection2 , and it will be done on after clicking the save button.

1 Like

Hi Geoval,
The best solution for you is using Data Hooks .
In afterInset Hook you can use the fields of the item that was added and save it to the other collection
Good luck!
Roi

Hello Roi,

Good day!
I know I’m asking too much, but could you please help me write the code to achieve the afterInset Hook function?
7 data fields will transfer the information from database1 to databse2 .

Hi Geo , I don’t know if you want to do it by yourself or you want that user perform this action by is own on your website !? I’m also interested by your request but probably in a diffferent circumstances… From my side I have created a JSON import/export fill form to allow user to export (export button) DB1 informations into text box and with import button to save into DB2. To do this all fields Id should match from DB1 to DB2. If you want to do it by yourself that’s really easy, Use the new CSV import/export function into the the Sandbox Db list. I will follow this post if Roi can help you about this function and will help you to perform if I can…

Hi Geo,
Unfortunately we are not able to code on your behalf.
Here is the hook’s function:

export function myCollection_afterInsert(item, context) { 
    
    // some changes to the received item. You can access item.field1 item.field2 etc.
    
    return item;
}

Good luck!
Roi

Hi there you can use this code, let me know if you need help

$w.onReady(function () {
let itemObj
$w(‘#dataset1’).onReady( () => {

$w(‘#button4’).onClick(()=>{
itemObj = $w(‘#dataset1’).getCurrentItem();
console.log(itemObj)
console.log(itemObj.title)
console.log(itemObj.make)
console.log(itemObj.model)

$w(“#dataset3”).onReady(() => {
$w(‘#dataset3’).setFieldValue(‘title’, itemObj.title)
$w(‘#dataset3’).setFieldValue(‘make’, itemObj.make)
$w(‘#dataset3’).setFieldValue(‘model’, itemObj.model)
$w(‘#dataset3’).save()

})
})

$w(‘#button4’).onClick(()=>{$w(‘#input1’).value = $w(‘#dataset1’).getCurrentItem().title})
$w(‘#button4’).onClick(()=>{$w(‘#input2’).value =$w(‘#dataset1’).getCurrentItem().make})
$w(‘#button4’).onClick(()=>{$w(‘#input3’).value=$w(‘#dataset1’).getCurrentItem().model})
})

});