approval and reject button in notification

tghadage124
Tera Contributor

Hi Guys, 

here I am trying to send notification on the update of the record where notification will go to the manager of the requestor name with approval and reject button on the notification : 

 

here is the email script : 

 

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

    // Fetch the requisition and company details
    var requisition = new GlideRecord('x_jade_procurement_it_purchase_requisition');
    requisition.get('sys_id', current.requisition);

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

    // Building the email message
    var emailBody = "";

    // Add requisition details table
    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><th>Category</th><th>Subcategory</th><th>Department</th></tr>";
    emailBody += "<tr>";
    emailBody += "<td>" + requisition.number + "</td>"; // Requisition number
    emailBody += "<td>" + requisition.requestor.name + "</td>"; // Assuming requestor is a reference to the user
    emailBody += "<td>" + requisition.department_assigned_to + "</td>"; // Department assigned to
    emailBody += "<td>" + requisition.short_description + "</td>"; // Short description
    emailBody += "<td>" + requisition.delivery_location + "</td>"; // Delivery location
    emailBody += "<td>" + requisition.category + "</td>"; // Category
    emailBody += "<td>" + requisition.subcategory + "</td>"; // Subcategory
    emailBody += "<td>" + requisition.department + "</td>"; // Department
    emailBody += "</tr>";
    emailBody += "</table>";

    // Approve and Reject buttons (use mailto to trigger actions)
    var instance = gs.getProperty("instance_name");
    var link = "https://" + instance + ".service-now.com";
    var mark = email.watermark;
    var emailAddress = instance + "@service-now.com";
    var number = current.sysapproval.number;

    // Button HTML: Approve and Reject
    emailBody += "<h3>Approval Action</h3>";
    emailBody += "<table cellspacing='10'><tr>";

    // Approve button
    var mailLink1 = '<a style="font-size: 10pt; font-family: helvetica; color: white; background-color: #008000; padding: 8px 20px; text-align: center; text-decoration: none; cursor: pointer;" ';
    mailLink1 += 'href="mailto:' + emailAddress + '?subject=Re: ' + number + ' - approve' + '&body=%0A%0A' + mark + '"><strong>APPROVE</strong></a>';
    emailBody += "<td>" + mailLink1 + "</td>";

    // Reject button
    var mailLink2 = '<a style="font-size: 10pt; font-family: helvetica; color: white; background-color: #FF0000; padding: 8px 20px; text-align: center; text-decoration: none; cursor: pointer;" ';
    mailLink2 += 'href="mailto:' + emailAddress + '?subject=Re: ' + number + ' - reject' + '&body=%0A%0A' + mark + '"><strong>REJECT</strong></a>';
    emailBody += "<td>" + mailLink2 + "</td>";

    emailBody += "</tr></table>";

    // Set the email body
    email.setBody(emailBody);

})(current, template, email, email_action, event); 
 
email is triggered but its not showing the body ? can someone please help me on this !! 
Screenshot (443).png
 
3 REPLIES 3

Runjay Patel
Giga Sage

Hi @tghadage124 ,

 

you forgot to add in last template.print and pass your text body variable.

 

Accept the solution if it helped.

its still not working

Hi @tghadage124 ,

 

First check whether mail script is getting called or not. Just comments all script and print one single like.

If that works then check all gliderecord object giving value of not.

 

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

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
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

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