How Can I set this Button into a Link( Accept/ Reject Link Email Notification)

Harsha1
Tera Contributor

Hi Community,

 

I have created this email script and Script Include. Instead of image I want text "Click here to Accept", "Click here to Reject". and  I have added some changes but it is not working.

 

Can anyone suggest me where I have to make changes ?

 

var img = "/Accept.png";

var response = "accept";

var emailbod = "I accept this request.";

template.print(ApprovalRejectObject(img, response, emailbod));

 

and script Include,

function ApprovalRejectObject(image, response, emailbod) {
 
    var instance = gs.getProperty("instance_name");
    var link = "https://" + instance + ".service-now.com";
    var mark = email.watermark;
    var number = current.number;
    var emailAddress = instance + "@service-now.com";
    if (current.getTableName().indexOf("sysapproval") != -1) {
        number = current.sysapproval.number;
    }
 
 
    var mailLink = '<a href="mailto:'+ emailAddress + '?subject=Re:' + number + ' ' + response +'&body=' +  emailbod +  mark + '"><img src="' + link + image + '"></a>';
return mailLink;
 
 
}
 
 
Regards,
Harsha
1 ACCEPTED SOLUTION

Riya Verma
Kilo Sage
Kilo Sage

Hi @Harsha1 ,

 

Hope you are doing great.

 

In the email script, you mentioned that instead of an image, you want to include the text "Click here to Accept" and "Click here to Reject." To achieve this, you need to replace the code for the image with the respective text. Please tru using below reference script:

 

var response = "accept";
var emailbod = "I accept this request.";

var acceptText = '<a href="mailto:' + emailAddress + '?subject=Re:' + number + ' ' + response + '&body=' + emailbod + mark + '">Click here to Accept</a>';

response = "reject";
emailbod = "I reject this request.";

var rejectText = '<a href="mailto:' + emailAddress + '?subject=Re:' + number + ' ' + response + '&body=' + emailbod + mark + '">Click here to Reject</a>';

template.print(acceptText + " | " + rejectText);

 

 
Please mark the appropriate response as correct answer and helpful, This may help other community users to follow correct solution.
Regards,
Riya Verma

View solution in original post

3 REPLIES 3

John Zhang1
Kilo Patron
Kilo Patron

@Harsha1 I have ServiceNow YouTube videos how to use both buttons (Approval or Reject) in an email notification for your reference.

 

https://www.youtube.com/watch?v=70tyNbYUjpc

 

Shraddha Kadam
Mega Sage

Hello @Harsha1 

 

I have used only Email script for Approve and Reject Buttons.

Please find below script for your reference :

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

  
    //OOB system property to guide to uri and to the case
    var linktoCase = gs.getProperty('glide.servlet.uri') + "/esc?id=hrm_ticket_page&table=" + '${hr_service.topic_detail.topic_category.coe}' + "&sys_id=" + '${sys_id}';

    //Email for instance
    var Email = gs.getProperty("sn_hr_core.hr_email").substring(16).slice(0, -1);

    //email link
    var EmailLink = '<a style="color:#001EFF;text-decoration: none;"href=mailto:"' + Email + '">' + Email + '</a>';

   
    

    /************************************************************************
    /* Button Section Approve Completion and Reject Completion buttons
    /*   that load an email respectively
    /***********************************************************************/
    var approvalbuttonText = gs.getMessage('Accept');
    var rejectbuttonText = gs.getMessage('Reject');

    //Accept Completion Button
    var watermark = email.watermark; //Body of email that has the watermark for the user that is approving

    var Approvehref = "mailto:" + Email + "?subject=Re:${number}%20-%20Accept%20%20Completion&amp;body=" + watermark;
    var ApproveAnchor = Approvehref;
    ActiveButtonHyperlink = ApproveAnchor;

    /*********************************************
	Newly added to display a link for accept.  Comment out the lines in this section when adding buttons back.
    *********************************************/
    var AccepthrefLink = '<a href=' + '"mailto:' + Email + "?subject=Re:${number}%20-%20Accept%20%20Completion&amp;body=" + watermark + '">' + approvalbuttonText + '</a>';

    template.print(AccepthrefLink);
    template.print('&nbsp;&nbsp;&nbsp;&nbsp;');


    /*end of newly added to display a link*/
    //Reject Completion Button
    var Rejecthref = '<a href=' + '"mailto:' + Email + "?subject=Re:${number}%20-%20Reject%20%20Completion&amp;body=" + watermark + '">' + rejectbuttonText + '</a>';

    template.print(Rejecthref);
    template.print('<br></br>');

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

 

Please mark my answer helpful and accept the solution.

 

Thank you.

If my response was helpful, please mark it as correct and helpful.
Thank you.

Riya Verma
Kilo Sage
Kilo Sage

Hi @Harsha1 ,

 

Hope you are doing great.

 

In the email script, you mentioned that instead of an image, you want to include the text "Click here to Accept" and "Click here to Reject." To achieve this, you need to replace the code for the image with the respective text. Please tru using below reference script:

 

var response = "accept";
var emailbod = "I accept this request.";

var acceptText = '<a href="mailto:' + emailAddress + '?subject=Re:' + number + ' ' + response + '&body=' + emailbod + mark + '">Click here to Accept</a>';

response = "reject";
emailbod = "I reject this request.";

var rejectText = '<a href="mailto:' + emailAddress + '?subject=Re:' + number + ' ' + response + '&body=' + emailbod + mark + '">Click here to Reject</a>';

template.print(acceptText + " | " + rejectText);

 

 
Please mark the appropriate response as correct answer and helpful, This may help other community users to follow correct solution.
Regards,
Riya Verma