The Zurich release has arrived! Interested in new features and functionalities? Click here for more

How to specify contains in client script for multi-value list field

jas101
Tera Expert

Hi guys, we are introducing a multi-select 'Impacted regions' field to our INC form (on a Major Incident tab).

Currently we have a script that sets e-mail recipients based on the Priority and a Customer field 'Member field' (which is a one value field).

We will want to update this client script off of the Impacted regions field (also on the INC form) instead of Customer Member firm so my question is how can we update it e.g. how can I specify 'contains' in the below example instead of == where the Newvalue could be up to 5 values and not just one?

if((newValue == 'TESTMEMBERFIRM') && (priority == 7)){

g_form.setValue('u_to', 'test@test.com');

}

In other words how could I say newValue contains 'USA' and 'Canada' - I'm not sure how the values in a multi-select list field are parsed.

Many thanks in advance,

DS

29 REPLIES 29

Michael Ritchie
ServiceNow Employee
ServiceNow Employee

use the JavaScript indexOf() function.   The value of -1 means it is not found, 0 and beyond will be the index location.



newValue.indexOf("USA") > -1


Many thanks for the rapid reply Michael - can I just add || for or then and does it matter what order the values may be added/show in the list if using this method?


Correct || is for Or and && is for and.   Order doesn't matter so you really just care if the index is greater than -1



So your script could be:


if((newValue.indexOf("USA") > -1 || newValue.indexOf("Canada") > -1) && (priority == 7)){


Many thanks Michael, look forward to giving this a try tomorrow!