Storing data in Dataset from dynamic page

Hi All,
I have a dynamic page connected to #dynamicDataset (read & write access). The underlying collection of the dataset contains a field “trx_status”, and I would like to add a status text “Confirmed” to that field.

For some reason I cannot get this to work - does anyone spot an issue in my code?

export function button3_click(event, $w) {
//Test 1
const currentItem = $w(“#dynamicDataset”).getCurrentItem();
currentItem.trx_status = “Confirmed”

//Test 2
$w(“#dynamicDataset”).setFieldValue(“trx_status”, “Confirmed”);
$w(“#dynamicDataset”).save();

}

Hi Gregor:

Just to be clear is trx_status the data collection field name or field key? These are different often and you should be using the field key (as an example you can have a field named " Trx Status " but the field key for code will be " trxStatus ".

Assuming trx_status is the key name and spelled correctly, I would do two things. First I would remove the $w parameter from the click handler. This is deprecated and may cause side effects if the scope for $w is wrong.

Then I would use console.log to print out the value of currentItem to make sure the item you want to update is the one the dataset thinks it is.

You might have other code or page bindings that are conflicting with this on your page (perhaps you have a dataset binding to the same element that is not in your code?).

You might not have the correct permissions on the data collection itself (who can write to the collection? Admin, Member, Visitor, Anyone?).

Hope one of these ideas helps. If not share the console log info, and a link to the published page and we can make a more informed assertion.

Cheers