I want to add an email script in my Email template

Pooja Khatri
Tera Contributor

Hi All , 

 

I have a requirement , where I have created an email template , and  in my email template I want to have the email script.

In my  email script I have created approve and reject links 

 

Script written in my email script : apprvl_email_outlook

 

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

    // Define the approval and rejection URLs using GlideSystem's 'getBaseURL()' method

    var baseUrl = gs.getProperty('glide.servlet.uri');

    var approvalUrl = baseUrl + 'sysapproval_approve.do?sys_id=' + email.sysapproval;

    var rejectionUrl = baseUrl + 'sysapproval_reject.do?sys_id=' + email.sysapproval;

   

    // Create the HTML for the "Approve" and "Reject" links

    var body = "<tr style='padding-top:10px;padding-bottom:10px;'><td width='100%' style='width:100.0%;padding:0in 5.4pt 0in 5.4pt;padding-bottom:15px;'>";

    body += "<p class='MsoNormal' align='center' style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;text-align:center'>";

    body += "<span style='font-size:12.0pt;color:black'></span>";

    body += "<a href='" + approvalUrl + "'>Approve</a> | <a href='" + rejectionUrl + "'>Reject</a>";

    body += "</span></p></td></tr>";

    email.body = body;

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

 

This email script I am trying to call in my email template in the below way :

 

PoojaKhatri_0-1698136479684.png

but this is not working , my data like short summary , description those details are not getting printed and only the links to approve and reject are getting printed .

 

How can I fix this ?

 

 

3 REPLIES 3

AnveshKumar M
Tera Sage
Tera Sage

Hi @Pooja Khatri 

You need to use template.print() instead of setting the email.body.

 

Try the below script in your mail Script.

 

 

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

 

    // Define the approval and rejection URLs using GlideSystem's 'getBaseURL()' method

 

    var baseUrl = gs.getProperty('glide.servlet.uri');

 

    var approvalUrl = baseUrl + 'sysapproval_approve.do?sys_id=' + email.sysapproval;

 

    var rejectionUrl = baseUrl + 'sysapproval_reject.do?sys_id=' + email.sysapproval;

 

   

 

    // Create the HTML for the "Approve" and "Reject" links

 

    var body = "<tr style='padding-top:10px;padding-bottom:10px;'><td width='100%' style='width:100.0%;padding:0in 5.4pt 0in 5.4pt;padding-bottom:15px;'>";

 

    body += "<p class='MsoNormal' align='center' style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;text-align:center'>";

 

    body += "<span style='font-size:12.0pt;color:black'></span>";

 

    body += "<a href='" + approvalUrl + "'>Approve</a> | <a href='" + rejectionUrl + "'>Reject</a>";

 

    body += "</span></p></td></tr>";

 

    template.print(body);

 

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

 

Please mark my answer helpful and accept as solution if it helped you 👍

Thanks,
Anvesh

Hi @AnveshKumar M - the issue is not with my email script , it is with my email template  - when I am trying to use my email script in my email template .. then it is only pasting the details (approve and reject links) in my email notification .. but it is not pasting other details above it .. which is short description , description etc .

 

Can you please help me with that fix .

@Pooja Khatri even if it is email template you just change the line I highlighted to template.print(body) and try once.

 

Thanks,
Anvesh