- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2022 12:28 AM
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
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2022 12:41 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2022 02:20 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2022 02:53 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2022 03:29 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2022 04:27 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2022 05:22 AM
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?