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-11-2017 09:13 AM
Thanks I figured it out.. so am getting back:
"Priority = 1 u_impacted_regions: f69521b437d0200044e0bfc8bcbe5d6e" i.e. what I'm putting as the sys ID in the scrip. Is it because the field is on a different section do you think?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-11-2017 09:14 AM
You can still use >-1 for sys IDs yeah?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-11-2017 10:06 AM
Oh guess what, turns out the essential hidden field 'u_to' had been removed from the INC form, someone took it off not knowing it was used to populate the recipients in the major incident e-mails! I didn't realise this because the UI policy always hides that field! Doh.
OK so it is now populating thee-mail address but I have realised that if using that method I wold have to account for every combination of regions and needed required email addresses so I need a smarter way to handle the below... if you have any ideas that would be really appreciated.
Rather than saying set to given e-mail addresses is there a way to say add this e-mail address if the region is found ie concatenate?!
Thank-you in advance.
If Priority = P1 (i.e., major incident):
If Service Regions includes | Set u_To as |
All regions (you could just check length of string or look for 4 commas?) | Global email address |
ELSE | |
Australia | Aus email |
Canada | Canada email |
EMEA | Emea email |
South Africa | South Africa email |
USA | Usa email |
AND THEN always add | Misc email |
In non SN script something like the below would be ideal. Pseudo Script:
// declare variable
var sTo
// Get value set in 'service regions' field
var pr = g_form.getValue('u_service_regions');
//See if it's all regions
if (pr.length > 31) {
sTo = 'globalmajorincident@test.com'
} else {
if (pr.includes(Australia) !== 0) {
sTo.concat(', aus@test.com')
}
if (pr.includes(Canada) !== 0) {
sTo.concat(', canada@test.com')
}
if (pr.includes(EMEA) !== 0) {
sTo.concat(',emea@test.com')
}
if (pr.includes(South Africa) !== 0) {
sTo.concat(',sa@test.com')
}
if (pr.includes(USA) !== 0) {
sTo.concat(',usa@test.com')
}
}
If (sTo.length > 0) {
sTo.concat(', vip@test.com')
} ELSE {
//Something is wrong!!! Such as, the service doesn't have any regions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-11-2017 10:30 AM
Lets back up a bit, what is the ultimate goal with your use case? From the list you are populating a field with a list of email addresses it sounds. What happens next? How is this list of email addresses used?
You could create a field on the location that stores this email address. Then in email notifications "dot walk" through your location list, get the email addresses and use those to send your notification. This will completely simplify what you are doing and not duplicate a list of emails on the form. But again I don't know enough about what you are trying to accomplish.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-11-2017 10:40 AM
Sure, sounds good! It is to set the correct e-mail addresses for major incident communications using e-mail client templates that contains pre-populated content (and importantly can be triggered manually anytime during a major incident from the INC form via the e-mail client template icon).
There is a hidden field on the INC form (u_to) which has it's value set by the client script you have kindly been helping me with.
This client script was based on priority and 'member firm' of the customer, but is now only to be based on the Impacted region values I have mentioned + we now only have 1 Priority for major incident (as opposed to 4!) so that part is redundant as I guess we can say Priority == 1 as the client script condition.
The 'To' field in the e-mail client is set to the values in the hidden u_to field.
Hope this makes sense?