How to specify contains in client script for multi-value list field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-10-2017 10:13 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-10-2017 10:15 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-10-2017 10:18 AM
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-10-2017 10:22 AM
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)){
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-10-2017 10:28 AM
Many thanks Michael, look forward to giving this a try tomorrow!