Hi!,
I am trying to use to the command “SetFieldValue” in my dynamic page. When I failed to connect my first dataset to another dataset I decided to use the “SetFieldValue” command.
This is my code:
export function button1_click(event, $w) {
$w(‘#dataset1’).setFieldValue(‘SongName’,$w(‘#input4’).value);
$w(‘#dataset1’).save();
}
when I do it the wrong field is updated. The Database made a new field called “[SongName]” and the new data is shown inside it.

What can I do to solve this problem?
Hey Josh,
Welcome to the Wix Code forums. Glad to have you aboard.
You need to use the Field Key and not the Field Name:
$w('#dataset1').setFieldValue('songName',$w('#input4').value);
Notice that the first letter of the Field Key is not a capital.
Here’s how to find the Field Key:
Good luck,
Yisrael
Hi, Yisrael . I did tempted your code to avoid duplicate records in my collections, successfully. Thank you very much. But now, I’m experiencing something like above and it is not working for me. In my application, I have two address types and if one is the same as the other, you just check a box and the address 2 is completed with the same data. When I submit to store in the collection, it creates a new field to each one like that and my main fields stay empty. Please, take a look in my code:
$w.onReady( function () {
$w(‘#dataset1’).onBeforeSave(() => {
$w(‘#dataset1’).setFieldValue(‘enderecoObra’, $w(‘#input4’).value);
$w(‘#dataset1’).setFieldValue(‘cidadeObra’ , $w(‘#input14’).value);
$w(‘#dataset1’).setFieldValue(‘bairroObra’ , $w(‘#input17’).value);
$w(‘#dataset1’).setFieldValue(‘estadoObra’ , $w(‘#dropdown2’).value);
$w(‘#dataset1’).setFieldValue(‘cepObra’ , $w(‘#input1’).value);
$w(‘#dataset1’).setFieldValue(‘whatsapp’ , $w(‘#input7’).value);
})
});
export function checkbox1_change(event, $w) {
if ($w(“#checkbox1”).checked === true ){
$w(“#input5”).value = $w(“#input4”).value;
$w(“#input15”).value = $w(“#input14”).value;
$w(“#input18”).value = $w(“#input17”).value;
$w(“#dropdown3”).value = $w(“#dropdown2”).value;
$w(“#input6”).value = $w(“#input1”).value;
} else {
$w(“#input5”).value = “”;
$w(“#input15”).value = “”;
$w(“#input18”).value = “”;
$w(“#dropdown3”).value = “”;
$w(“#input6”).value = “” ;
}
}
export function checkbox2_change(event, $w) {
if ($w(“#checkbox2”).checked === true ){
$w(“#input9”).value = $w(“#input7”).value;
} else {
$w(“#input9”).value = “”;
}
}
export function button1_onClick(event) {
$w(“#dataset1”).save();
}
it seems right (I compared with $w(’ #dataset1 ‘).setFieldValue(‘songName’,$w(’ #input4 ').value); you post above) but it not works. Can you help me? Thank you so much.