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

Its service catalog workflow.

Yes its correct 

find_real_file.png

Hi,

then you can update as this

I assume all these values are the name of the companies to which that variable refers

answer = ifScript();

function ifScript(){

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

	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';
}

Regards
Ankur

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

Its now not showing error now but it should go to Yes. Its taking value as "No".

find_real_file.png

Hi,

variable refers to which table?

which field of that table you need to check against for that text?

example: if field refers to core_company table then you want to compare against name field?

are you comparing correct value?

answer = ifScript();

function ifScript(){

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

    gs.info(val); // what comes here

    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';
}

Regards
Ankur

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

The variable refers to core_company variable.

And company table has field "name" and if the name field contains those values.

The problem here is many company has same value for eg:

company name is leisure, entertainment and cinema

or company name is leisure and entertainment

company name is leisure and cinema

similarly multiple companies like this with variation in wordings. So is because of this it is not working correctly?