need to call email script in notification???

Srvs
Kilo Guru

Hi

I have email script as follows

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

I need to call this script in notifications, please help me out how can i do this?? with example or screen shot.

Any help is greatly appreciated (with examples)

--venky

1 ACCEPTED SOLUTION

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hello Venkatesh



Create mail scripts in System Policy > Email > Notification Email Script->


(function runMailScript(current, template, email, email_action, event) {


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


  }


})(current, template, email, email_action, event);





Now you can call the above mail script in email notification(Message HTML) as ${mail_script:script name}


Here replace script name with the exact name of the notification email script you have created in step 1.


View solution in original post

8 REPLIES 8

 

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 .

NeelanshP_1-1672830170137.jpeg

 

nayanawadhiya1
Kilo Sage

Hey Venkatesh,



Use like this -


find_real_file.png



${mail_script:Your mail script name}




OR



You can that script directly into MESSAGE HTML when you submit it will automatically convert into MAIL SCRIPT.


Hi 

 

I am calling email script  ${mail_script:incident_take_me_to_the_incident}   in email body ,its not working for Kinsten version.

Help is appreciated..

 

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

If I have answered your question, please mark my response as correct so that others with the same question in the future can find it quickly and that it gets removed from the Unanswered list.



If you are viewing this from the community inbox you will not see the correct answer button.   If so, please review How to Mark Answers Correct From Inbox View.