Operator in If Script

vcaracci75
Tera Expert

I wrote the following if script in one of my workflows:

function ifScript() {

  if (current.variables.groups_needed == 'ROLE_CAIS SSO') {

  return 'yes';

  }

  return 'no';

}

The "Groups Needed" filed can contain more than one answer. what operator can I use instead of "==" so that if the field contains ROLE_CAIS SSO it will still return true?

Thanks,

Vince

1 ACCEPTED SOLUTION

Another thing you might consider is adding toLowerCase() so you don't have to worry about the case:



if (current.variables.groups_needed.toString().toLowerCase().indexOf('role_cais sso') > -1) {


View solution in original post

4 REPLIES 4

Brad Tilton
ServiceNow Employee
ServiceNow Employee

Hi Vince,



You can do a sort of contains search using something like:



if (current.variables.groups_needed.toString().indexOf('ROLE_CAIS SSO') > -1) {



That being said, this would only work if the groups_needed variable is a single or multiline text variable. If it's a list collector variable it's going to store values as a comma separated list of sys_ids.


It's a multiline text filed. I will try this.



Thanks,



Vince


Another thing you might consider is adding toLowerCase() so you don't have to worry about the case:



if (current.variables.groups_needed.toString().toLowerCase().indexOf('role_cais sso') > -1) {


That worked! Thanks!