Issue with Email Client Templates and multiple email addresses
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-28-2017 11:36 AM
Hi -
We've an email client template that we've set up for a particular catalog request item.
We would like the "To" address of this email client template to default to both the "opened_by" and "variables.requested_for" fields if they're different.
We've had email client templates working for years, and adding the conditions so that this particular email client template runs on this particular catalog request item seems to be working fine.
...
The problem is trying to put MULTIPLE values in this field when using javascript. How do you correctly separate the email values?
Here's our email script for the "To"(recipients) field:
javascript:
if(current.variables.requested_for.email!="" && current.opened_by.email=="") {
current.variables.requested_for.name+"<"+current.variables.requested_for.email + ">"
}else if(current.variables.requested_for.email=="" && current.opened_by.email!="") {
current.opened_by.name+"<"+current.opened_by.email + ">"
}else if(current.variables.requested_for.email!="" && current.opened_by.email!="") {
current.variables.requested_for.name+"<"+current.variables.requested_for.email + ">"+";"+current.opened_by.name+"<"+current.opened_by.email + ">"
}else{
""
}
The first 2 conditions work and send email just fine. The third - where it would send 2 emails at once - does not.
I've highlighted in red the problem character. If the character we put there is a semicolon, everything LOOKS like it works fine. The email popup has the users in the field, correctly displayed ("Name1; Name2;" etc), but the email doesn't SEND to them. In the email log, the Recipients field looks the same as most recipients fields, except the field separating the users is a semicolon instead of a comma. But these recipients never were actually added to the email header field in the email, so it didn't get to the appropriate folks, and ServiceNow says that was because "a semicolon in the recipients field is not supported, only a comma."
Ok, fine. So I try to do the same thing except use a COMMA, instead... And it then doesn't work correctly in the email popup; the To field ends up blank.
What IS the correct character to use here? Or, if there is no character that will work, how can I get the functionality I need?
Much thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-29-2017 09:10 PM
Hi All,
It appears that using a semi colon or comma within the a javascript string isn't recognized by ServiceNow for the email fields so the last condition in your statement isn't working. Comma separation is required and accepted outside of javascript for multiple addresses so what you can do is break up your javascript code into several if statements that are comma separated. ServiceNow will then look at each piece of javascript code and process it correctly, if the condition in your if statement isn't met it will be simply dropped from the "To" field.
Example
Before:
if(current.variables.requested_for.email!="" && current.opened_by.email=="") {
current.variables.requested_for.name+"<"+current.variables.requested_for.email + ">"
}else if(current.variables.requested_for.email=="" && current.opened_by.email!="") {
current.opened_by.name+"<"+current.opened_by.email + ">"
}else if(current.variables.requested_for.email!="" && current.opened_by.email!="") {
current.variables.requested_for.name+"<"+current.variables.requested_for.email + ">"+";"+current.opened_by.name+"<"+current.opened_by.email + ">"
}else{
""
}
After breaking up these if/else into separate javascript statements that are comma separated.
javascript: if(current.variables.requested_for.email!="" && current.opened_by.email == "") { current.variables.requested_for.name + "<"+current.variables.requested_for.email+">"}, javascript: if(current.variables.requested_for.email=="" && current.opened_by.email!=""){ current.opened_by.name+"<"+current.opened_by.email+">" }, javascript: if(current.variables.requested_for.email!="" && current.opened_by.email!="") { current.opened_by.name+"<"+current.opened_by.email+">"}, javascript: if(current.variables.requested_for.email!="" && current.opened_by.email!="") { current.variables.requested_for.name + "<"+current.variables.requested_for.email+">" }
Knowing that if a statement is not satisfied it will be simply dropped from the "To" field, we can simplify this code further to add the email of the requested_for or opened_by users if it exists.
Simplified:
javascript: if(current.opened_by.email!="") { current.opened_by.name+"<"+current.opened_by.email+">" }, javascript: if(current.variables.requested_for.email!="") {current.variables.requested_for.name+"<"+current.variables.requested_for.email+">"}
A final thing to note is that you need to ensure your javascript code has no line breaks as anything after that line break is dropped.
Hope that helps,
Paul
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-29-2017 09:30 PM
Simply try to put below into 'To' field
opened_by,variables.requested_for