- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2018 02:21 PM
I need to pull a service catalog variable on "sc_req_item" table to email notification. I am reading that the variable first needs to be defined on email script before adding to the email notification which makes sense but I am not sure how to write the mail script. Can someone help me with this? The variable name is "Item_Requested". Thanks.
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2018 12:12 PM
Thanks for all the responses back to my post. The request changed from adding just one variable to the notification to adding all variables on the catalog item to the notification. I used the mail script below to achieve that objective.
for (var key in current.variables) {
var v = current.variables[key];
template.print('\n' + v.getGlideObject().getQuestion().getLabel() + ": " + v.getDisplayValue() + " <br />");
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2021 10:14 AM
Hi Nishant,
I am having the same problem, where you able figure out the solution? Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-10-2021 07:28 AM
Hi Mekonnen,
I have the same requirement, can you please let me know how did you develop this so that it will be helpful to me.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-10-2021 07:28 AM
Hi Nishant,
I have the same requirement, can you please let me know how did you develop this so that it will be helpful to me.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2023 06:10 AM
I am using this email script and it is mostly working. Issue is it isn't populating all of my variables. There are a few variables within a variable set and none of those are showing in my email notification and then there are a few more variables attached directly to the catalog item that aren't showing. I did notice that only ten are showing in my email so maybe this use of key limits at ten. Anyone know if that's true or why I wouldn't see every variable? Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago - last edited 2 weeks ago
In ServiceNow, catalog variables are not normal fields on sc_req_item, so you cannot reference them directly like ${current.item_requested}. You must access them through the variables object, either directly in the notification or via a Mail Script.
Since your variable name is Item_Requested, here are the correct approaches.
If the notification is triggered on sc_req_item, the simplest method is to reference it directly in the Email Notification body:
${current.variables.Item_Requested}
That works if the variable name in the catalog item is exactly Item_Requested (variable name, not the label).
If you prefer to use a Mail Script, create a new Email Script and use this:
(function runMailScript(current, template, email, email_action, event) {
var itemRequested = current.variables.Item_Requested;
if (itemRequested) {
template.print(itemRequested);
} else {
template.print("No item requested value found.");
}
})(current, template, email, email_action, event);Then in your Email Notification body, call the mail script like this:
${mail_script:your_script_name}

