Notification script problem

avinashdubey103
Tera Guru

Hi I have written the below script :

Instead of giving clickable link that open mails it is printing that text :

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



    var softwareURL = '';

    var pricePerMonth = '';

    var duration = '';

    var totalAmount = '';

    var businessNeed = '';



    var grRitm = new GlideRecord('sc_req_item');

    grRitm.addQuery('number', current.sysapproval.getDisplayValue());

    grRitm.query();



    if (grRitm.next()) {

        softwareURL = grRitm.variables.u_software_service.getDisplayValue();

        pricePerMonth = grRitm.variables.u_price.getDisplayValue();

        duration = grRitm.variables.u_duration.getDisplayValue();

        totalAmount = grRitm.variables.u_total_amount.getDisplayValue();

        businessNeed = grRitm.variables.u_business_needs.getDisplayValue();

    }



    var approverName = current.approver.getDisplayValue();



    var emailBody = "<p>Dear " + approverName + ",</p>" +

                    "<p>On " + current.sysapproval.sys_created_on.getDisplayValue() + ", your employee " + current.sysapproval.task_for.getDisplayValue() + " submitted the following Request:</p>" +

                    "<p><a href='/sc_req_item.do?sys_id=" + current.sysapproval.getUniqueValue() + "'>" + current.sysapproval.number + "</a> – Request new GenAI software.</p>" +

                    "<p>Software name: " + softwareURL + "</p>" +
                    "<p>Business needs: " + businessNeed + "</p>" +
                    "<p>Usage period: " + duration + "</p>" +
                    "<p>Software monthly cost: " + pricePerMonth + "</p>" +
                    "<p>Software total cost: " + totalAmount + "</p>" +

                    "<p>If you choose to approve the purchase of this software, " + current.sysapproval.task_for.getDisplayValue() + " (" + current.sysapproval.task_for.user_name+ ") will be able to go ahead and order it directly from the vendor, and then submit the receipts for reimbursement via the My Expense portal. The cost of the subscription will be loaded into " + current.sysapproval.task_for.getDisplayValue() + "'s Profit Center / division.</p>" +

                   
                    "<p>Please approve or reject/decline the request.</p>" +

                    "<div><label style='color: #324450;'> ${mailto:mailto.approval.accept}</label>&nbsp;&nbsp;&nbsp;&nbsp;<label style='color: #324450;'>${mailto:mailto.rejection.accept}</label></div>" +


                    "<p>Regards,</p>" +

                    "<p><b>Amdocs IT</b></p>";



    email.setSubject("A request for GenAI software is pending your approval");

    email.setBody(emailBody);

    email.setContentType("text/html");

    email.send();



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

Screen shot:


avinashdubey103_0-1703666957134.png

 

8 REPLIES 8

T_Fesenko
Tera Contributor

Hi @avinashdubey103 ,

It's because this is treated as a string which is the content of label

 "<div><label style='color: #324450;'> ${mailto:mailto.approval.accept}</label>&nbsp;&nbsp;&nbsp;&nbsp;<label style='color: #324450;'>${mailto:mailto.rejection.accept}</label></div>" 

Look into this article: Solved: adding a mailto link in Description section of Cat... - ServiceNow Community
Solved: mailto email template - ServiceNow Community

It seems like mailto is used as a link (<a> tag will do), not as a content of <label>, <p>, <div>, ect.

Best, 

Tym

Amit Verma
Kilo Patron
Kilo Patron

Hi @avinashdubey103 

 

Can you try changing the mailto tag from ${mailto:mailto.approval.accept} to ${mailto:mailto.approval} and check ? 

 

Thanks & Regards

Amit Verma


Please mark this response as correct and helpful if it assisted you with your question.

checked same output :

avinashdubey103_0-1703668188024.png

 

Prathamesh G
Kilo Sage
Kilo Sage

Hello @avinashdubey103,

 

You need to use the <a> tag to mark any text as a link.

Please refer to the below documents for further information:

1. https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0684584

2. https://docs.servicenow.com/bundle/vancouver-platform-administration/page/administer/notification/co...

If my above answer resolve your issue, please mark the solution as 'Accepted Solution' and also mark it as 'Helpful'.

 

Thank You!

Prathamesh.