Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

email script not getting triggered

tghadage124
Tera Contributor

Hi Guys i am trying to send notification in below format : 

Screenshot (397).png 

here is email script : 

(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
    /* Optional EmailOutbound */
    email, /* Optional GlideRecord */ email_action,
    /* Optional GlideRecord */
    event) {

    // Add your code here
    var company = new GlideRecord('core_company');
    company.get('sys_id', current.company);


    var requisition = new GlideRecord('incident');
    requisition.get('sys_id', current.sys_id);

    var emailBody = "";

    emailBody += "<h2>Company Information</h2>";
    emailBody += "<p><strong>Company Name: </strong>" + company.name + "</p>";
    emailBody += "<p><strong>Company Address: </strong>" + company.address + "</p>";
    emailBody += "<p><strong>Email: </strong>" + company.email + "</p>";

    emailBody += "<h2>Requisition Details</h2>";
    emailBody += "<table border='1' style='width:100%; border-collapse: collapse;'>";
    emailBody += "<tr><th>Requisition Number</th><th>Requestor Name</th><th>Department Assigned To</th><th>Short Description</th><th>Delivery Location</th></tr>";

    emailBody += "<tr>";
    emailBody += "<td>" + requisition.number + "</td>";
    emailBody += "<td>" + requisition.assigned_to + "</td>";
    emailBody += "<td>" + requisition.assignment_group + "</td>";
    emailBody += "<td>" + requisition.short_description + "</td>";
    emailBody += "<td>" + requisition.state + "</td>";
    emailBody += "<td> " + requisition.description + "</td>";
    emailBody += "</tr>";

    emailBody += "</table>";


    email.setBody(emailBody);
    template.print(emailBody);

})(current, template, email, email_action, event); 
 
here is the email notification : 
Screenshot (402).png
but when preview my notification data is not getting displayed : 
 
Screenshot (404).png
4 REPLIES 4

Rajesh Mushke
Mega Sage

Hi @tghadage124,

 

you can directly hardcode the other all fields except the quantity table and values can be dynamic from the email template. Only for Quantity table you need a dynamic table which needs to be pulled from Email script. Share the image text here so that i will be able to help you further. 



Thanks,
Rajashekhar Mushke
Rising star : 2022 - 2024
Community Leader -2018
Connect me on LinkedIn : Rajashekhar Mushke

Runjay Patel
Giga Sage

Hi @tghadage124 ,

 

I have tested your code it is working. Hope you have attached the mail script properly in your notification.

RunjayPatel_1-1729683106538.png

 

RunjayPatel_2-1729683150144.png

 

RunjayPatel_0-1729683023108.png

 

I have triggered it on incident update.

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.

Regards
Runjay Patel - ServiceNow Solution Architect
LinkedIn: https://www.linkedin.com/in/runjay
YouTube: https://www.youtube.com/@RunjayP

-------------------------------------------------------------------------

for some fields like company fields they are not getting populated and for some requisition they are getting populated as sys_id. 

 

please guide.

do you have company field on the incident table or fetching it from different table?

for the fields which you are getting the sys_id, use the field_name.getDisplayValue();



Thanks,
Rajashekhar Mushke
Rising star : 2022 - 2024
Community Leader -2018
Connect me on LinkedIn : Rajashekhar Mushke