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

If condition in workflow, If variable contains value (X or Y) it must trigger catalog task

Not applicable

Hello,

I have a requirement to trigger catalog task in workflow if Department Variable (referencing to cmn_department) contains value "Information Technology" or "GST" then it must trigger the catalog task oresle no

I have written below If condition advanced script but its failing 

Reference variable Department has Question and Name value both as Department. Image attachedfind_real_file.png

function ifScript() {
var Department = current.variables.Department.getDisplayValue();
if (Department.toString().indexOf('Information Technology') >-1 || Department.toString().indexOf('GST') >-1){
return 'yes';
}
return 'no';
}

 

Please advice.

1 ACCEPTED SOLUTION

Hello @Ankita Gupte ,

Then try below script 

answer = ifScript();

function ifScript() {
var dept = new GlideRecord('cmn_department');
dept.addQuery('sys_id',current.variables.Department);
dept.query();
if(dept.next())
{
if(dept.name.indexOf("Information Technology") || dept.name.indexOf("GST"))
{
return 'yes';
}
else
{
return 'no';
}
	
}

Please mark my answer correct if it helps you

 

View solution in original post

9 REPLIES 9

Not applicable

Hello Mohith,

This will be true only if Name is "Information Technology" or "GST".

I have many departments which has name containing "Information Technology" or "GST" and there will be more coming up so everytime I have to edit the filters keeping track of it.

Due to which I want to apply if condition that department contains "Information Technology" or "GST".

Hello @Ankita Gupte ,

Then try below script 

answer = ifScript();

function ifScript() {
var dept = new GlideRecord('cmn_department');
dept.addQuery('sys_id',current.variables.Department);
dept.query();
if(dept.next())
{
if(dept.name.indexOf("Information Technology") || dept.name.indexOf("GST"))
{
return 'yes';
}
else
{
return 'no';
}
	
}

Please mark my answer correct if it helps you

 

Not applicable

I used includes instead of indexof and it worked fine.

dept.name.indexOf

Thank You, It helped.

Palak Gupta
Tera Guru

Hi @Ankita Gupte ,

You can do a dot - walking in IF activity instead of scripting.

find_real_file.png

Please mark my answer correct and helpful if this resolves your query.

Regards,

Palak

 

Not applicable

This will take only with Name "Information Technology" or "GST"

I have many departments which has name containing "Information Technology" or "GST" and there will be more coming up so everytime I have to edit the filters keeping track of it.

Due to which I want to apply condition that department contains "Information Technology" or "GST".