Updates the value of a field.
This function behaves slightly differently depending on where it is used.
When working client-side
Server-side you can target a field on any page of the form that already exists in the session (ie one that has already been visited). It's not possible to update fields on future form pages that have not been visited yet as these pages and fields don't exist yet. The targeted field's handler will not be triggered, because handlers are only triggered client-side.
If a page repeats, and there is more than one instance of it, the
If you need to set field values on pages that haven't been visited yet, use .setPageValues.
All of the standard form fields submit their values as strings, and the platform expects field values to be strings. When you set a field's value, make sure it is a string or you will encounter errors.
Executed
Client-side and server-side.
Arguments
| Argument | Type | Description |
|---|---|---|
| fieldName | String, required | The name of the field to be updated |
| fieldValue | String, required | The new value of the field |
| pageInstance | Integer, optional | Used with repeating pages. The instance (zero-based) of the page the field is on that you'd like to update. Defaults to the current page instance if called on the repeating page that holds the field. If you call this function from elsewhere on your form and the page instance is not supplied, the update will fail |
Example
In this example
function (helper) {
helper.setFieldValue('FIELD4', helper.getVariable('myVariable'));
}
This example has been added to the next function of a wizard button. It updates the value of a field on a page that has just been visited.
function(helper, defaultPage, sessionData) {
helper.setFieldValue('FIELD2', 'A new value');
return defaultPage;
}
