setFieldValue( )
Updates the value of a field in the current item.
Description
The setFieldValue
function sets the value of a field in the current item.
Setting a field value fires an onItemValuesChanged
event when the page
elements connected to the field have been updated with the new value.
Setting the value of a field in a dataset item does not immediately set
that value in the collection that the dataset is connected to. You still
need to call the dataset save()
function or any other function that
performs a save to have the new value reflecting in the collection.
Calling setFieldValue()
on a read-only dataset causes an error.
Note:
A dataset needs to load its data before you call its
setFieldValue()
function. Usually a dataset finishes loading a short time after the page it is on finishes loading. So if you callsetFieldValue()
inside the page’sonReady()
event handler, the dataset might not be ready yet.To call
setFieldValue()
as soon as possible after a page loads, use the dataset'sonReady()
function inside the page’sonReady()
event handler to ensure that both the page and the dataset have finished loading.
Syntax
function setFieldValue(fieldKey: string, value: *): void
setFieldValue Parameters
NAME
TYPE
DESCRIPTION
The field ID of the field to update.
The new value.
Returns
This function does not return anything.
Return Type:
Related Content:
Was this helpful?
1$w("#myDataset").setFieldValue("title", "New Title");
1$w("#myDataset").setFieldValue("title", "New Title");2$w("#myDataset").save();
1$w.onReady( () => {2 $w("#myDataset").onReady( () => {3 $w("#myDataset").setFieldValue("title", "New Title");45 } );67} );