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  

If condition script on workflow

Ankita Gupte
Kilo Sage

Hello,

I want to use if condition based on value populated in var_employee_company_name.

If the value contains any of the below word it should skip further task which I can skip based on Yes/NO output of if check

I need help to write the script i.e. if var_employee_company_name contains Leisure or finance or lifstyle or ventures it should be Yes value orelse No

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

something like this if it's a field

if it's a catalog variable and you are using workflow on RITM then use this

var val = current.variables.var_employee_company_name.toString();

answer = ifScript();

function ifScript(){

	var val = current.var_employee_company_name.toString();

	if(val.indexOf('Leisure') > -1 || val.indexOf('finance') > -1 || val.indexOf('lifstyle') > -1 || val.indexOf('ventures') > -1){
		return 'yes';
	}
	return 'no';
}

Regards
Ankur

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

View solution in original post

13 REPLIES 13

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

something like this if it's a field

if it's a catalog variable and you are using workflow on RITM then use this

var val = current.variables.var_employee_company_name.toString();

answer = ifScript();

function ifScript(){

	var val = current.var_employee_company_name.toString();

	if(val.indexOf('Leisure') > -1 || val.indexOf('finance') > -1 || val.indexOf('lifstyle') > -1 || val.indexOf('ventures') > -1){
		return 'yes';
	}
	return 'no';
}

Regards
Ankur

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

This is and condition or OR condition in script?

Hello Ankur, Its failing.

find_real_file.png

I have used below script because this are all words which company name will contain.

answer = ifScript();

function ifScript(){

var val = current.var_employee_company_name.toString();

if(val.indexOf('Ventures') > -1 || val.indexOf('finance') > -1 || val.indexOf('fashion') > -1 || val.indexOf('lifestyle') > -1 || val.indexOf('leisure') > -1 || val.indexOf('MAF LEC') > -1 || val.indexOf('MAF LEC KSA') > -1 || val.indexOf('cinema') > -1){
return 'yes';
}
return 'no';
}

Hi,

is workflow on some table?

is the field name correct? var_employee_company_name

Logic I shared is correct; you just want to use correct field name or variable name

Regards
Ankur

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