List Collector Array in Run Script on Workflow

NonaJohnson
Kilo Expert

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

9 REPLIES 9

Hi Nona,

Yes check that variable name is correct or not;

Also where this script is written?

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

yes the variable name is correct - I did double check that just in case.  The script is written on a run script on the RITM workflow

Hi Nona,

That list collector variable is referring to which table?

Is that task_ci table?

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Nona,

Any update on this?
Can you mark answer as correct, 👍 helpful if you were able to achieve the requirement. This enables other members to learn from this thread.

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Suseela Peddise
Kilo Sage

Hi,

'select_the_server' variable on catalog form is referring to which table? Is it referring to 'task_ci' table?

 

If I have answered your question, please mark my response as correct and/or helpful.

Thanks,

Suseela P.