The CreatorCon Call for Content is officially open! Get started here.

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

Chuck Tomasi
Tera Patron

You may have to create a series of "if" statements that each evaluate for one of the values in the variable list.



if list contains "A", then go one way


If list contains "B", then go another way



I thought you could script a switch activity, but it doesn't look like it.



Reference:


Workflow Concepts - ServiceNow Wiki


Creating a Workflow - ServiceNow Wiki


Using Workflow Activities - ServiceNow Wiki


ctomasi Hey Chuck my main problem is i am unable to fetch values from LIST COLLECTOR or SLUSH BUCKET value as there is no backend value of these A,B,C,D and E shown in list collector left bucket.



give me some code to get values in workflow so that i can compare it and fire approvals?


If your workflow is on the RITM and the variables are on the RITM, then you should have access to the values as



current.variables.variable_name



Have you tried doing some quick debug output in the workflow or testing it in scripts background to ensure you can get at these values?



This may help do some debugging...


Faster Server Side Script Development and Test


As Chuck mentioned, you can use current.variables.<list_collector> to fetch the values.



FYI, list collector will have sys_IDs as the back end.