Record Producer script to pass value of list collector to Configuration Item and Affected CI related list

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-30-2018 11:07 PM
We are trying to create a record producer wherein 1 variable in the form is a list collector. Now when the user submits the form it will should be able to parse the values entered on the variable (list collector) and do the following:
1) Set the first item entered (a configuration item in our case) as the value of the Configuration Item field in the change request record
2) Set the succeeding items as values on Affected CI related list
We figured this should be done via a script in the record producer, any ideas on how to do this?
Here's one script we found here on another community discussion How to map the list collector from the record producer into the change form(we need to split the lis... , we need a way for the values of sec_ci to be passed to Affected CI related list of change_request table:
var CIList = current.variables.<listCollectorName>;
var array = CIList.split(",");
var sec_ci = '';
for (var i=0; i < array.length; i++) {
if(i==0){
<Configuration Item field> = array[i]; // initialize Configuration Item field
}
else {
if (sec_ci != ''){sec_ci += ','+array[i];}
else {sec_ci = array[i];}
}
}
<secondary CI field> = sec_ci; // initialize secondary CI field
If only ServiceNow allows dot walking to the related lists when selecting a variable to map on Record Producers, then this would not need custom script development.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-05-2018 05:23 AM
I am not if we can get the sys_id of change_request in record producer until or unless we have a change record created. Instead I think we can try to have After Insert BR on change_request table to get the value from list collector and loop though them to create affected CI's record along with change_request sys_id?
Can you please share the screenshot of Record Producer and create record in task_ci table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-12-2020 06:07 AM
Hi JC,
Me and my colleagues just solved the issues in the script. The below script works perfect and creates records in the Affected CI list based on the list collector in the record producer.
var CIList = '' + producer.<listCollectorName>;
var ciArray = CIList.split(",");
for (var i = 0; i < ciArray.length; i++) {
var gr = new GlideRecord('task_ci');
gr.initialize();
gr.ci_item = '' + ciArray[i];
gr.task = '' + current.sys_id; //PASS THE SYS_ID OF CHANGE REQUEST
gr.insert();
}
I hope this helps!
Regards
Christian