Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Script for if activity in workflow

Abhishek8
Tera Contributor

Below is my script which i am using in the if activity of workflow,this workflow runs on Requested item table

I have a catalog variable project_id, Iwant to check if the value in project_id contains INT then only if part should get executed,but this code is not working

 

 

answer = ifScript();

function ifScript() {
if (current.variables.project_id.contains('INT')) {
return 'yes';
}
else{

return 'no';
}
}

 

Kindly try to fix my code.so i can proceed further.

1 ACCEPTED SOLUTION

Hi Abhishek,

Below is the sample code

 

answer = ifScript();

function ifScript() {
if (current.variables.project_id.toString().indexOf('INT') > -1 || current.variables.project_id.toString().indexOf('PRE') > -1 || current.variables.project_id.toString().indexOf('REF') > -1 ) {
return 'yes';
}
else{

return 'no';
}
}

 

View solution in original post

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Abhishek,

can you update code as below; you can use indexOf() function

answer = ifScript();

function ifScript() {
if (current.variables.project_id.toString().indexOf('INT') > -1) {
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

Abhishek8
Tera Contributor

Thanks Ankur for the quick reply 

One more thing is that i want to add multiple conditions in if block,like project_id having any one these  INT,PRE,REF 

Hi Abhishek,

Below is the sample code

 

answer = ifScript();

function ifScript() {
if (current.variables.project_id.toString().indexOf('INT') > -1 || current.variables.project_id.toString().indexOf('PRE') > -1 || current.variables.project_id.toString().indexOf('REF') > -1 ) {
return 'yes';
}
else{

return 'no';
}
}