calling email script into notification
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2023 12:26 AM
Hello Team,
I just make two fields on Catalog with variables Requester name and Item, Here I have to populate both on notification calling email script.
I have created one email script below: email script name :- {custom_catalog_item_variables}
(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
// Get Variables
var requester = current.variables.u_requester_name.getDisplayValue(toString());
var item = current.variables.u_items.toString();
template.print(requester);
template.print(item);
})(current, template, email, email_action, event);
Now on notification I am calling this email script with correct details like : - ${mail_script:custom_catalog_item_variables}
Now if i want to do preview Notification then these above two values showing Undefined. Please help me to resolve this error. attched screenshot with this .
Please help me out to print those undefined vales correctly.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2023 12:38 AM
@Neelansh P Email script calling does not work during notification preview. Please try triggering notifications and check the mailbox or email logs of ServiceNow.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2023 12:39 AM
Hi @Neelansh P ,
Refer to this thread :https://www.servicenow.com/community/developer-forum/need-to-call-email-script-in-notification/m-p/2...
You can learn more from this : https://developer.servicenow.com/dev.do#!/learn/courses/tokyo/app_store_learnv2_automatingapps_tokyo...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2023 12:58 PM
Neelansh,
I think you should only have template.print(); once. You have toString() and getDisplayValue() syntax incorrect on requester. Make sure the variable names are correct (u_requester_name, u_items) and that they have values for the RITM you're previewing.
Try this
var result = "";
var requester = current.getDisplayValue('u_requester_name');/// toString () is not needed, getDisplayValue() returns a string
//is item singular or plural?
var item = current.variables.u_items.toString();//I don't remember if getValue or getDisplayValue work with variables or not
result = requester + "\n" + item;
template.print(item);