Unable to save just one field in my dataset

Hi,

I’ve managed to build a string “businessCatsChosen” with the content I wish to insert in my dataset. The field name in the dataset is “vStoreBuisCat”

I’ve tried using the following to save the data:
$w(wixData).onBeforeSave( () => { $w(wixData).setFieldValue(‘vStoreBuisCat’, businessCatsChosen); $w(wixData).save();
} );

I’ve tried inserting the lines above within :

a)
export function SaveCategoriesButton_click(event) {

}

and b)

$w.onReady( function () { //TODO: write your page related code here…

});

Neither seem to work.

I’d really appreciate some hep here.
Thanks,

Riaz

Managed to sort it out. Articulating the problem helped.

a) I put the code below in the button click event;
b) ‘datasetname’ was the name of the dataset I used on the page.

export function SaveCategoriesButton_click(event) {

$w("#datasetname").onBeforeSave( () => { 
$w("#datasetname").setFieldValue('vStoreBuisCat', businessCatsChosen); 
} ); 

$w(“#datasetname”).save();

}

Thanks in any case. There’s a lot of helpful advice in this forum which I frequently refer to.