We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

Passing list collector variable value in Workflow

baqar rizvi
Mega Expert

Hey guys,

                                  I am working on a task in which when I select options from Slushbucket or list collector variable in SR   and order it.

then as per selected options Approvals goes to different users??

while searching through the community I tried different Approval Scripts but didn't worked. Please help? ctomasi

find_real_file.png

I am creating workflow on sc_req_item

find_real_file.png

1 ACCEPTED SOLUTION

In your user approval activity, check the advanced check box and put this script in there



answer=[];


var arr= current.variables.SR.getDisplayValue().split(',');


for(i=0; i<arr.length; i++){


if(arr[i].trim()=='A'){


answer.push(sys_id of user X);


continue;


}


if(arr[i].trim()=='B'){


answer.push(sys_id of user Y);


continue;


}


if(arr[i].trim()=='C'){


answer.push(sys_id of user z);


continue;


}


}


View solution in original post

12 REPLIES 12

Steven1
Tera Expert

You will need to do something similar to this.



****Loop inside the list collector field and create task.*********



var myString = current.variables.c_item.toString();


var mySplitResult = myString.split(",");


for (i = 0; i < mySplitResult.length; i++){


  var   taskCi = new GlideRecord("task_ci");


  taskCi.initialize();


  taskCi.ci_item = mySplitResult[i];


  taskCi.task = current.sys_id;


  taskCi.insert();


}


Abhinay Erra
Giga Sage

Before I get into the coding part, what table is the list collector variable on?


For List Collector Variable I have used a custom table named u_software having 6 records as Software name - A,B,C,D,E and Other.


baqar rizvi
Mega Expert

Thanks a lot Guys for such prompt replies I just starting learning scripting in SNOW so looking forward for support from you all.....



This is what i understood from the discussion above :



var list= current.variables.software.toString(); //to fetch values from list which are in format(A,B,C)


var resultsplit= list.split(","); // to split the values based on comma



now tell how to fire APPROVAL based on selected value


A -------> X User


B--------> Y User


C--------> Z User



whats Next ???


You don't have any specific conditions on whom to send when a value is selected in the list collector? Because what you have now is just hard coding like if A go to user X