
- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 05-27-2022 05:55 AM
This is part 2 of How to read a record and set the value in an input field in UI Builder?
Create a Page variable to store the field value
- Go to Client state parameters (card icon on the left toolbar)
- Click +Add
- Set Name to "date_format"
- Set Initial value to "@data.getsystemproperty.output.value"
Update the page variable when the value changes
- Select the Input field
- On the config panel on the right, go to the Events tab
- In the section "Input value set", Click on "+Add a new event handler"
- Search for "update", then select Update client state parameter
- For "Client State Parameter Name", select "date_format"
- For "New Value", click on the "dynamic data binding" icon and type "@payload.value"
- Click Add.
- Click Save
Create a script to update the value
- Go to Page Scripts ( icon </> on the left toolbar)
- Click +Add
- Set Script name to a meaningful name. Ex: Update Property
- For now, to show how the different pieces connect together quickly, we'll simply print a message, so add the following snippet n the code editor:
function handler({api, event, helpers, imports}) {
console.log("Update Property Script");
console.log("date_format = " + api.state.date_format);
} - Notice how the call to "api.state.<name of variable> gives access to our page variables
Connect the Button to the Script
- Select the "Save" button
- Go to the config panel on the right
- Click on the Events tab
- Click on "+Add a new event handler"
- in the new dialog, in the "</> Script" section, select "Update Property"
- Click Add
- Save your UIB Page
Test
- Click on the Open button to preview the page
- In the preview page, update the field value (ex: dd-mm-yy)
- then Click on the Save button
- You will see the value printed in the console. All the required elements are connected. We now need to make the update permanent by
- adding an "update record" data resource
- and calling it with the new value stored in the page variable
Add an "Update record" data resource
- Go to Data Resources ( icon database on the left toolbar)
- Click +Add
- Search for "Update record"
- Select "Update record"
- Click Add
Call the "Update record" data resource
- Update the Page script with the following code:
function handler({api,event, helpers, imports}) {
let fields = "value=" + api.state.date_format;
api.data.update_record_1.execute({
table: "sys_properties",
recordId : api.data.getsystemproperty.output.sysId,
templateFields: fields,
useSetDisplayValue: false
});
} - Save the page
- Click on the Open button to preview the page
- In the preview page, update the field value (ex: yyyy-mm-dd)
- Click on the Save button
- Check your record, and voila it was updated.
- 10,165 Views

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Just a quick note, you should be able to bypass the last page script and call the update record data resource directly from the button component. If you're just passing a single value to the record like in this example you don't need to use a page script to call the data resource as you can pass parameters to the data resource through the event handler. An example can be found in this exercise from my CreatorCon lab this year.
The page script can be really useful if you need to do some data manipulation before calling the data resource.

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Thanks Brad. I forgot to mention that in this particular example, the sys_properties table is not accessible in the list of table when calling the update record data resource directly hence the use of a Page Script.

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Ok that makes sense. There are definitely use cases where you have to use a page script, I just want everyone to try directly through the event handler first.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Great article @Marc Mouries!
Some additional information I hope will be helpful: If you want to update multiple fields on the target table you need to use an encoded query. See my example here:
function handler({
api,
event,
helpers,
imports
}) {
var local_ans = api.state.assmtQuestionList[0].questionList;
var answerCount = local_ans.length;
for (let i = 0; i < answerCount; i++) {
var response = local_ans[i].response;
var value = local_ans[i].value;
var sysId = local_ans[i].sys_id;
let fields = "response=" + response +"^value="+ value;
api.data.update_record.execute({
table: "x_snc_award_mgmt_deliverable_rubric_responses",
recordId: sysId,
templateFields: fields,
useSetDisplayValue: false
});
}
}
This specific line shows how to specify multiple fields using "^" as the separator:
let fields = "response=" + response +"^value="+ value;