Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

list collector variable base if or switch condition in workflow not working.

pratikyadav
Tera Contributor

I am trying to use a table list collector variable base if or switch condition in Service Catalog workflow , where i am checking if the options selected under list collector field contain X then move to next activity to approval stage else move to fulfilment stage. But unfortunately both If and switch activity is not working. Once X selected stil it going to fulfilment stage. Below is the workflow i am using.

 

find_real_file.png

find_real_file.png

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Pratik,

For this you need to use the if condition with script

answer = checkValue();

function checkValue(){

var values = current.variables.<variableName>.toString();

var split = values.split(",");

var X = sysId to be searched

var arrayUtil = new ArrayUtil();

var value = arrayUtil.contains(split, X);

if(value)

return 'yes';

else

return 'no';

}

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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

View solution in original post

5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Pratik,

For this you need to use the if condition with script

answer = checkValue();

function checkValue(){

var values = current.variables.<variableName>.toString();

var split = values.split(",");

var X = sysId to be searched

var arrayUtil = new ArrayUtil();

var value = arrayUtil.contains(split, X);

if(value)

return 'yes';

else

return 'no';

}

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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

Hi Ankur,

 

Thank you for providing the solution, But unfortunately its not working for me, may be i am putting anything wrong in the script. Please find the below script which i am using.

 


answer = checkValue();
function checkValue(){
var values = current.variables.application_role.toString();
var split = values.split(",");
var X = current.varibales.application_role.sys_id;
var arrayUtil = new ArrayUtil();
var value = arrayUtil.contains(split, X);
if(value)
return 'yes';
else
return 'no';
}

 

Note :- The table we are using under list collector is our own company customized table , and i am unable to find the sys id for the specific record / option of the list collector, hence using "current.varibales.<varibalename>.sys_id
 

Hi Pratik,

Can you add log statements and check what values you are getting?

Regards

Ankur

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

Hi 

I see an error in spelling .

You have written varibales.application_role.sys_id;

try with variables.application_role.sys_id;