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

Hi,

you want to search for exact value or contains?

because for contains the script should work fine

try to add some gs.info()

Regards
Ankur

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

@Ankita Gupte 

Hope you are doing good.

Did my reply answer your question?

If my response helped please close the thread by marking appropriate response as correct so that it benefits future readers.

Regards
Ankur

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

@Ankita Gupte 

Hope you are doing good.

Did my reply answer your question?

If my response helped please close the thread by marking appropriate response as correct so that it benefits future readers.

Regards
Ankur

 

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

shloke04
Kilo Patron

Hi @Ankita Gupte 

Please use the script shared below:

answer = ifScript();

function ifScript(){

	var getVariable = current.variables.VariableName.getDisplayValue().toString();

	if(getVariable.indexOf('Ventures') > -1 || getVariable.indexOf('finance') > -1 || getVariable.indexOf('fashion') > -1 || getVariable.indexOf('leisure') > -1){
		return 'yes';
	}
	return 'no';
}

Replace Variable Name with your correct Variable Name in script above

 

Similarly add other OR conditions for the values you need to validate and see if this works.

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke