
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2014 06:18 AM
Hi all,
I think I'm trying to do something pretty simple.
I have a few variables on my catalog item form that I need to pull into an email notification. One of the fields being 'alt_poc_phone'
I've tried GlideRecord and current.variable_pool.alt_poc_phone and neither seems to work.
I've also referenced the following wiki page (Scripting for Email Notifications - ServiceNow Wiki), but something's not clicking (on my part).
Any help is greatly appreciated (with examples)
MM
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2014 04:47 AM
Mandar/Adam-
Follow up to my post. For some reason the mail script is working now. I'm not sure why it wasnt' working earlier. I guess I had a typo or something.
Here's the script that works:
<mail_script>
var item = new GlideRecord("sc_req_item");
item.addQuery("request", current.sys_id);
item.query();
while(item.next()) {
var catalogItem = item.number + ': ' + item.cat_item.getDisplayValue();
var misc = item.variable_pool.alt_poc;
template.print(catalogItem + "<br/> Field: " + misc);
}
</mail_script>
Really appreciate the feedback guys, couldn't have done this without you-
On to my next challenge

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2015 07:43 AM
Hey Kumar,
Let's see if this will help. I'll walk through an email notification that fires when a new sc_request is created, but in this email, I want to list certain variables captured in the sc_req_item entry associated w/ the sc_request as well as a link back to the requested item.
The email notification itself fires on inserts to the sc_request table
The email notification 'What it will contain' will/could use an email template that you'll create
The email template will/could contain references to an email script.
The script will/could contain something like this:
var gr = new GlideRecord("sc_req_item");
gr.addQuery("sys_id",current.sys_id);
gr.query();
while(gr.next()) {
var catalogItemLink = '<a href=" ' + <your url> + 'catalog/catalog.do?sysparm_document_key=sc_req_item, ' + gr.getUniqueValue() + ' ">' + gr.number + '</a>' + ': ' + gr.cat_item_getDisplayValue();
template.print( " + catalogItemLink + "<br/>");
template.print( <b>Requested For</b>: " + gr.variable_pool.<name of variable>.getDisplayValue() + "<br/>"; //this is a reference field so I have to use getDisplayValue
template.print( <b>Alternate POC</b>: " + gr.variable_pool.<name of variable>.alt_poc_name + "<br/>"; //this is a regular single line text field so i can call the name of the field directly w/out getDisplayValue
template.print( <b>Urgency</b>: " + gr.variables.header); //you can also try this call instead of variable_pool to see if you get what you need
}
Hope this helps; keep us posted-
matthew
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2015 07:48 AM
Hi Matthew
I used something like this and it worked
<mail_script>
//template.print("Summary of Requested item:\n");
var gr = new GlideRecord("sc_req_item");
gr.addQuery("sys_id", current.sysapproval);
gr.query();
while(gr.next()) {
//template.print(gr.number + ": " + gr.quantity + " X " + gr.cat_item.getDisplayValue() + "\n");
//template.print(" Options:\n");
for (key in gr.variables) {
var v = gr.variables[key];
if(v.getGlideObject().getQuestion().getLabel() != '' && v.getDisplayValue() != '') {
//template.space(4);
if(v.getGlideObject().getQuestion().getName()=="user_first_name")
template.print(' ' + v.getGlideObject().getQuestion().getLabel() + " = " + v.getDisplayValue() + "\n");
if(v.getGlideObject().getQuestion().getName()=="user_last_name")
template.print(' ' + v.getGlideObject().getQuestion().getLabel() + " = " + v.getDisplayValue() + "\n");
if(v.getGlideObject().getQuestion().getName()=="email")
template.print(' ' + v.getGlideObject().getQuestion().getLabel() + " = " + v.getDisplayValue() + "\n");
if(v.getGlideObject().getQuestion().getLabel()=="PIN")
template.print(' ' + v.getGlideObject().getQuestion().getLabel() + " = " + v.getDisplayValue() + "\n");
}
}
}
</mail_script>
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2015 07:53 AM
Matthew
I have 1 more question if you can help of
In the approval reply email, I will have a field like below
NextApprover:
There, present approver will provide next approver email id and sends approval email to SN
I have to write a script to read the NextApprover: field value and populate it in ReadOnly field of submitted form.. this field will be left blank while submitting form.. I want to fill that field in this way as I mentioned
Is that something doable?? can we populate fields on form after submission??
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2015 07:20 AM
Hi anthony,
I hope you have an answer to this as I'm obviously really late to your response. The script will go in a Notification Email Script.
See: Scripting for Email Notifications - ServiceNow Wiki
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2017 04:46 AM
Thank you Mathew your script helped me a lot.