List Collector Array in Run Script on Workflow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2020 06:05 AM
Greetings:
I have been struggling with getting an array for a list collector on a catalog form to work. I want the below script to take the list of servers contained in the variable "select the server" and add them to the Affected CI's related list. If I select only one server in the list collector it will show that one server name in the related list, but if I select more than one it will not show the name of the server in the related list. So . . .choose one and the name of the server shows up, choose two and only one shows, but no server name. Can anyone tell me what I've got incorrect in the below script. I am using it on a run script within a workflow.
var answer =[];
var list = current.variables.select_the_server.toString(); \\ this is the variable name on the catalog form
var listArr = list.split(',');
for (var i=0;i<listArr.length;++i) {
var task_ci = new GlideRecord('task_ci'); \\ table name of Affected CI's releated List
task_ci.addQuery('sys_id',listArr[i]);
task_ci.query();
while(task_ci.next()){
answer.push(task_ci.ci_item.sys_id.toString());
}
}
Thanks
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2020 06:10 AM
Hi Nona,
Did you check what comes in answer array; the script looks good;
var answer =[];
var list = current.variables.select_the_server.toString(); \\ this is the variable name on the catalog form
var listArr = list.split(',');
for (var i=0;i<listArr.length;++i) {
var task_ci = new GlideRecord('task_ci'); \\ table name of Affected CI's releated List
task_ci.addQuery('sys_id',listArr[i]);
task_ci.query();
gs.info('Row Count is: ' + task_ci.getRowCount());
while(task_ci.next()){
answer.push(task_ci.ci_item.sys_id.toString());
}
}
gs.info('Answer array is: ' + answer);
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
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-24-2020 06:31 AM
Yes I did check both and row count is 0 and answer is empty - for some reason it doesn't pick up the selections - not even when I select just one (which does show in the related list) .
Thanks for looking at the script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2020 06:37 AM
Hi Nona,
where this script is written?
var list = current.variables.select_the_server.toString();
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-24-2020 06:49 AM
Not sure what you are asking - is that script incorrect?