Hi,
I need to assign one dataset reference type field with key from another dataset field on form submit.
Currently i am doing something like that:
$w(“#datasetEventsAudiths”).setFieldValue(“eventID”, $w(“#dynamicDataset”).getCurrentItem());
$w(“#datasetEventsAudiths”).save();
in AfterSaved event, but its not realy saved to database, although i can see it updated in the dataset collection
EventID is a reference field, so what value should i put in there?
There are several things I would like you to pay attention to:
First of all , A dataset needs to load its data before you call the setFieldValue() function.
Usually a dataset finishes loading a short time after the page it is on finishes loading. So if you call the function inside the page’s onReady() event handler, the dataset might not be ready yet.
The solution is to use the dataset’s onReady() function inside the page’s onReady() event handler to ensure that both the page and the datasets have finished loading.
Second , $w(" #dynamicDataset ").getCurrentItem() function return an object.
There for, in order to use the setFieldValue() function, you need to set as parameter your desirable field (object’s property) from the object.