How to populate catalog item fields in UI builder?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2023 05:38 AM
Hello Experts,
In UI builder I've added one of existing catalog items. I would like "release" field to update with provided sys_id. How can I populate CI field in UI builder?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2023 07:50 AM
To populate the "Release" field in the ServiceNow UI Builder with a provided sys_id, you can use a combination of UI Actions and Script Actions.
Here are the steps to achieve this:
- Create a UI Action: Go to "System Definition" -> "UI Actions" -> "New". Give it a name, choose the table you want to modify, and set the action type to "Script". In the script field, add the following code:
var ciSysId = "insert_sys_id_here"; // replace insert_sys_id_here with the actual sys_id you want to use
var gr = new GlideRecord('table_name'); // replace table_name with the name of the table you want to modify
if (gr.get(ciSysId)) {
g_form.setValue('release', gr.getValue('release'));
}
- Create a Script Action: Go to "System Definition" -> "Script Actions" -> "New". Give it a name, set the table to the same table you used in the UI Action, and set the "Order" to "1". In the script field, add the following code:
return {
type: 'UI_ACTION',
options: {
action_name: 'name_of_ui_action', // replace name_of_ui_action with the name you used for the UI Action
table: 'table_name', // replace table_name with the name of the table you want to modify
condition: 'sys_id=' + current.sys_id // this ensures the UI Action is only executed when the current record is saved
}
};
Add the Script Action to the form: Go to the form where you want to add the "Release" field and click on the gear icon in the top right corner. Choose "Configure Form Layout". In the "Header" section, add a new row and drag the "Script" widget into it. In the widget's properties, set the "Action" field to the name of the Script Action you just created.
Save the form: Click "Save" to save the changes you made to the form. Now when you create or edit a record in this table, the "Release" field will be automatically populated with the value from the record with the provided sys_id.
Please mark my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2023 03:39 AM
Is it AI generated response? How setting ui action will help populate catalog items variables in ui builder?