- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-08-2024 11:22 AM
I am looking at populating the requested item --> parent related list from a list collector variable on a catalog item when the catalog task gets closed. Any help on how to formulate the script would be appreciated.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-08-2024 11:32 PM
To populate the requested item parent related list from a list collector variable on a catalog item when the catalog task gets closed, you can use the following steps:
- Open the Requested Item (RITM) form in ServiceNow's Form Designer.
- Identify the related list where you want the selected items from the list collector variable to be displayed individually.
- Add a new client script to the RITM form.
- In the client script, use the onComplete event to trigger the population of the parent related list.
- Retrieve the selected items from the list collector variable using the getValue() method.
- Iterate through the selected items and create new records in the parent related list.
- Set the appropriate field values for each new record based on the selected items.
- Save the new records in the parent related list.
Here is an example of how the client script might look like:
function onComplete() {
var listCollectorVariable = g_form.getControl('<list_collector_variable_sys_id>');
var selectedItems = listCollectorVariable.getValue();
for (var i = 0; i < selectedItems.length; i++) {
var selectedItem = selectedItems[i];
var newRecord = new GlideRecord('<parent_related_list_table>');
// Set field values for the new record
newRecord.initialize();
newRecord.<field1> = selectedItem.<field1>;
newRecord.<field2> = selectedItem.<field2>;
// Set other field values as needed
newRecord.insert();
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-08-2024 12:38 PM
What do you have in the list collector?
If those are task records, you can create a onAfter BR and get the list collector using current.request_item.variables.<list collector name> and then for each element in the list collector, update the task record with requested item as parent record.
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-08-2024 11:32 PM
To populate the requested item parent related list from a list collector variable on a catalog item when the catalog task gets closed, you can use the following steps:
- Open the Requested Item (RITM) form in ServiceNow's Form Designer.
- Identify the related list where you want the selected items from the list collector variable to be displayed individually.
- Add a new client script to the RITM form.
- In the client script, use the onComplete event to trigger the population of the parent related list.
- Retrieve the selected items from the list collector variable using the getValue() method.
- Iterate through the selected items and create new records in the parent related list.
- Set the appropriate field values for each new record based on the selected items.
- Save the new records in the parent related list.
Here is an example of how the client script might look like:
function onComplete() {
var listCollectorVariable = g_form.getControl('<list_collector_variable_sys_id>');
var selectedItems = listCollectorVariable.getValue();
for (var i = 0; i < selectedItems.length; i++) {
var selectedItem = selectedItems[i];
var newRecord = new GlideRecord('<parent_related_list_table>');
// Set field values for the new record
newRecord.initialize();
newRecord.<field1> = selectedItem.<field1>;
newRecord.<field2> = selectedItem.<field2>;
// Set other field values as needed
newRecord.insert();
}
}