Need to create record in "task_cmdb_ci_service" table with the listcollector values
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2022 10:27 PM
Hello Community Leaders,
We have one List collector variable which is refering to cmdb_ci table to select multiple ci's in one of catalog item. when user select CI's and submit, The change record should be created & also "task_cmdb_ci_service" should be created with the values of CI's which i selected when request was submitted & with the change number.
I have created workflow for the same.
to create change record i am usign create task activity & to create record in "task_cmdb_ci_service" table i am using run script activity with below script.
var gr = new GlideRecord('task_cmdb_ci_service');
gr.initialize();
gr.cmdb_ci_service = current.variables.ci;
gr.task = workflow.scratchpad.number;// this number is from "create task activity"
gr.insert();
But it is not working as expected. Please help me here.
Thanks in advance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2022 10:44 PM
Hi,
Try the below script and store task sys_id in scratchpad instead number in "create task activity"
var listValues = current.variables.ci.toString();
var split = listValues.split(',');
for(var i in split){ //Iterates over every CI and creates Individual record for every CI
var gr = new GlideRecord('task_cmdb_ci_service');
gr.initialize();
gr.cmdb_ci_service = split[i]; //Stores individual CI as service
gr.task = workflow.scratchpad.sys_id;// this sys_id is from "create task activity"
gr.insert();
} //End of the for loop
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2022 10:45 PM
Hi,
update as this
var arr = current.variables.ci.toString().split(',');
for(var i=0;i<arr.length;i++){
var gr = new GlideRecord('task_cmdb_ci_service');
gr.initialize();
gr.cmdb_ci_service = arr[i];
gr.setDisplayValue('task',workflow.scratchpad.number);// this number is from "create task activity"
gr.insert();
}
OR
Store the task sys_id in workflow scratchpad instead of number and use this script
var arr = current.variables.ci.toString().split(',');
for(var i=0;i<arr.length;i++){
var gr = new GlideRecord('task_cmdb_ci_service');
gr.initialize();
gr.cmdb_ci_service = arr[i];
gr.setValue('task',workflow.scratchpad.sysId);// this number is from "create task activity"
gr.insert();
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-02-2022 01:42 AM
HI Ankur,
Thanks for your quick response,
I have tried with the scripts which you shared. but some how it was not working. it is not creating records in the "task_cmdb_ci_service" list.
Any suggestions here.
Thanks in advance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-02-2022 02:10 AM
Please share your latest script
Did you use sys_id to set?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader