- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2016 10:46 PM
I want to add a cc in email scripts.For this purpose i have written a email notification script as
var gr = new GlideRecord("incident");
gr.addQuery("sys_id",current.sys_id);
gr.query();
if(gr.next())
{
email.addAddress("cc",String(gr.caller), String(gr.caller.getDisplayValue()));
}
I am getting a cc field in my mail but getting the value stored database for the caller filed(it is a reference field).
How to get the name of the caller in the cc field?
Thanks in advance !!!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2016 10:54 PM
You have to do dot-walking as it is the reference field and in the cc field you should be put the email of the user -
var gr = new GlideRecord("incident");
gr.addQuery("sys_id",current.sys_id);
gr.query();
if(gr.next())
{
email.addAddress("cc",gr.caller.email.toString(), gr.caller.name.toString());
}
Mark if it is helpful or correct, feedback is appreciated
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2016 10:54 PM
You have to do dot-walking as it is the reference field and in the cc field you should be put the email of the user -
var gr = new GlideRecord("incident");
gr.addQuery("sys_id",current.sys_id);
gr.query();
if(gr.next())
{
email.addAddress("cc",gr.caller.email.toString(), gr.caller.name.toString());
}
Mark if it is helpful or correct, feedback is appreciated
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2016 10:56 PM
FYI, the best practice that can be followed when you do email scripting -
Try to script in Email Actions and Email Scripts like this -
While you are queueing the event, follow this -
1. parm1 should have To list of the recipients.
2. parm2 contains JSON structure of following format
{
addressedTo : "John",
sendCcList:''abc@123.com",
sendBccList: "123@abc.com"',
}
In the email action, check only Event parm 1 cotains recipients check box, uncheck Event parm 2 as recipients check box.
Go to the email scripts tables-
Write a new email script: notification_email_script //you can put any name and its advisable to separate the words with underscore
var jp = new JSONParser();
event.info = jp.parse(event.parm2);
event.addressedTo = event.info.addressedTo;
for (var i=0;i < event.info.sendCcList.length; i++)
email.addAddress("cc",event.info.sendCcList[i]);
for (var i=0;i < event.info.sendBccList.length; i++)
email.addAddress("bcc",event.info.sendBccList[i]);
Go back to the email action -
In the message HTML put the below line at the top-
${mail_script:notification_email_script}
FYI, refer this link for email scripting - Scripting for Email Notifications - ServiceNow Wiki
Happy scripting
Mark if it is helpful or correct, feedback is appreciated
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2016 11:12 PM
No need to GlideRecord again because you already have GlideRecord object of that incident record i.e. current. Following Mail Script should work for you.
<mail_script>
email.addAddress("cc",current.caller_id.email,current.caller_id.getDisplayValue());
</mail_script>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2016 10:52 AM
Hi Gurpreeet,
I am having the same issue. I would like to add a cc to an email notification and I would like it to add in the data from a custom variable from the request item. Can you help me with this?
Thanks!