- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2021 07:31 AM
I am very new to the Service Now administration.
im trying to send an email to one of my vendors when certain values are selected on my record producer form.
then i want to take other values from my record producer and send it in a formatted email to the vendor. without them getting all the information. i would say 90% of my variables in my record producer go into the description field in the resulting ticket, but the vendor I have doesn't need all of that, which is what is making this endeavor harder for me.
is anyone able to help me get started on how to do this, ive seen a few questions like this on the forums, but they are way ahead of where i am at. I pick up on these things quickly, so any guidance getting started would be highly appreciated.
Solved! Go to Solution.
- Labels:
-
Notifications
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2021 03:40 PM
I was able to get this to work with help from this post: https://community.servicenow.com/community?id=community_question&sys_id=fcff3be9db66fbc02be0a851ca961904
Sample of the code that worked for me:
In Record Producer:
var EmailData = {"Date" : DateField, "Position" : PositionInfoField, "ReportedBy" : ReportedByField, "Description" : DescriptionField, "Subj1" : Subject1Field, "Subj2" : Subject2Field};
var parser = new JSON();
var notificationContent = parser.encode(EmailData);
gs.log('JSON object:' + notificationContent);
gs.eventQueue('EmailEvent',current , notificationContent , '');
in Email Script:
(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
// Add your code here
var jsonObject=event.parm1;
// Parsing JSON object:
var obj = JSON.parse(jsonObject);
template.print(obj.Date+"<br>");
template.print(obj.Position+"<br>");
template.print(obj.ReportedBy+"<br>");
template.print(obj.Description+"<br>");
// Set Subject in resulting email
email.subject =obj.Subj1+" - "+ obj.Subj2;
})(current, template, email, email_action, event);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2021 08:20 AM
ok im following, now how do i get the different variables i stored to go into the subject & body of the email?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2021 08:26 AM
Awesome... we are almost there...
We cannot directly access the event parameters in the notification body. To do that, we have to create a Notification Email Script. (Make sure there are no spaces in the name of the record you are creating)
You need to reference this email script in your notification body by using:
${mail_script:yourEmailScriptName}
You can access your event parameter in the Email script by using:
var data = event.parm1
Check this out...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2021 08:38 AM
so i set up a new var for each piece of the array i built in the first step.
var Date = event.parm1;
var Name = event.parm2;
var description = event.parm3;
and in the body of the email how do i then use those variables?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2021 09:03 AM
template.print('This is gonna appear in the notification')
Create as many template.print() as you want... each prints in a new line
Check this out:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2021 09:10 AM
im having a problem accessing the values in the array i built. i realize now the array is stored in event.parm1 how do i access each of the 8
notificationContent.detail1 = data1;
....
notificationContent.detail8 = data8;
that i created in the first step?