Copy a database field to another database when clicking button

I have a dinamic page with a list of designers you can choose from, and when you open one designer in particular (another “read” dynamic page) there is a button to “select designer”. When pressed, I need for it to save the “Name” of the designer (belonging to the Designers database) to a field in a database called Proyects. I´ve being trying to get the code right from this post:

https://www.wix.com/corvid/forum/community-discussion/give-a-dataset-a-value-of-another-dataset-with-code

but it´s not working. All the database ID are correct. This is the code I tried:

export function button1_click(event, $w) {
$w.onReady( () => {
$w( "#designers ).onReady( () => {
let itemObj = $w( “#designers” ).getCurrentItem()
$w( ‘#designers’ ).setFieldValue( '#Name , $w( ‘#Name’ ).value)
$w( "#Proyects ).save()
} );

} );
}

I´m totally new at code so probably a few things are wrong!

Hello yuyog,

please show a peace of your 2 databases in a pic (each the first 2 rows and the header). And show the IDs of the relevant references (columns).

Ok, here a try without knowing all your data-structure.
Replace/fill the related datasets with your own.

Dataset-A = designer-database (READ-ONLY)
Dataset-B = proyects (WRITE-ONLY)

Set the right reference-IDs ! ! ! —> (look into your databases)

$w.onReady(function () {
 let itemObj
    $w('#button1').onClick(()=>{
        $w('#dataset1').onReady( () => {
            itemObj = $w('#dataset1').getCurrentItem();
            console.log(itemObj)
            console.log(itemObj.title)
        })

        $w("#dataset2").onReady(() => {
            $w('#dataset2').setFieldValue('title', itemObj.title)
            $w('#dataset2').save()
        })
    })
});

Press-F12 and go to CONSOLE, to see whats going on.
Can still have some failures, but should work.

This code do a copy of the curent item (“title”) of database-A to database-B (title). Change by your needs and optimize the code.

thank you so much for the magiiiiiiiiiiiic! it worked! :heart::heart::heart:

No problem my friend :grin:
And here i had forgot to show the example of it at work, sorry.
https://russian-dima.wixsite.com/meinewebsite/dublicate-database

Amazing!! Thank you so much!

Thank you for this! It worked like a charm! Appriciate it very much!

@rudjersimek
You are welcome.

@russian-dima Can you maybe help with this: https://www.wix.com/velo/forum/community-discussion/import-from-multiple-datasets-to-one-dataset

Thank you in advance!