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 like mentioned in the below picture. where i am getting data from core_company table and incident table. 

Screenshot (397).png

here is the 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);

})(current, template, email, email_action, event); 
 
but here I am only getting an notification like this where it seems to get an data from incident table not from core_company table  and not even in table format. like below 
Screenshot (398).png
 
 Screenshot (399).png
here is the notification where i am mentioning notification. which is getting triggered while insert and update in the incident. 
 
can you please guide where i am going wrong.
 
thanks!!
3 REPLIES 3

Tai Vu
Kilo Patron
Kilo Patron

Hi @tghadage124 

 

It looks like the $ is missing when you're calling the mail script in the Message HTML. Let's update it as follows:

From

 

{mail_script:it.purchase.requisition};

 

To

 

 

${mail_script:it.purchase.requisition};

 

 

Cheers,

Tai Vu

 

yes have changed the same thanks

Moin Kazi
Kilo Sage
Kilo Sage

Hi @tghadage124 ,

 

Remove the email template from the fields, and in the body, call the script as follows:

 

${mail_script:your_email_script _name} 

 

You don’t need to include a semicolon at the end while putting mail script in the html body.

 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

If you found my response **helpful**, I’d appreciate it if you could take a moment to select **"Accept as Solution"** and **"Helpful"** Your support not only benefits me but also enriches the community.

 

Thank you!
Moin Kazi

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~