calling email script into notification

Neelansh P
Tera Contributor

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 . Temp.JPG   

Please help me out to print those undefined vales correctly. 

3 REPLIES 3

Veer
Tera Guru

@Neelansh P  Email script calling does not work during notification preview. Please try triggering notifications and check the mailbox or email logs of ServiceNow.

ricker
Tera Guru

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);