Approval Name is not printing in the notification

avinashdubey103
Tera Guru

Hi , I am trying to print a notification , But the Approval name is not printing in it :

Notification :

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



    var softwareURL = '';

    var pricePerMonth = '';

    var duration = '';

    var totalAmount = '';



    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();

    }




    var approverName = current.sysapproval.getValue('approver').getDisplayValue();



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

        "<p>On " + current.sysapproval.sys_created_on.getDisplayValue() + ", your employee " + current.sysapproval.task_for.getDisplayValue() + " submitted a service request for:</p>" +

        "<p><a href='/sc_req_item.do?sys_id=" + current.sysapproval.getUniqueValue() + "'>" + current.sysapproval.number + "</a> – Request new Gen AI SW for " + softwareURL + ", for " + pricePerMonth + " USD per month and duration of " + duration + " months, with total cost of " + totalAmount + ".</p>" +

        "<p>If approved, the employee will have to subscribe by himself/herself and get reimbursed through My Expense.</p>" +

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

        "<div><a href='" + current.mailto.approval.accept + "'>Approve</a> | <a href='" + current.mailto.rejection.accept + "'>Reject</a></div>";



    email.setSubject("Manager Request for Service Approval");

    email.setBody(emailBody);

    email.setContentType("text/html");

    email.send();



})(current, template, email, email_action, event);
2 ACCEPTED SOLUTIONS

Ankur Bawiskar
Tera Patron
Tera Patron

@avinashdubey103 

simply use this

var approverName = current.approver.getDisplayValue();

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

Hi @avinashdubey103,

 

My mistake, you need to use -

var approverName = current.getDisplayValue("approver");

 

OR

try with as Ankur mentioned,

var approverName = current.approver.getDisplayValue();

 

If my response helps you resolve your issue. Kindly mark it as helpful & correct. It will be helpful to future readers! 👍🏻
Thanks,
Sagar Pagar

The world works with ServiceNow

View solution in original post

4 REPLIES 4

Sagar Pagar
Tera Patron

Hi @avinashdubey103,

 

You can try this way -

var approverName = current.sysapproval.getDisplayValue("approver");

 

If my response helps you resolve your issue. Kindly mark it as helpful & correct. It will be helpful to future readers! 👍🏻
Thanks,
Sagar Pagar

The world works with ServiceNow

Hi , Instead of printing Name it is printing RITM Number

 

avinashdubey103_0-1703138409272.png

code used :

 var approverName = current.sysapproval.getDisplayValue("approver");

Hi @avinashdubey103,

 

My mistake, you need to use -

var approverName = current.getDisplayValue("approver");

 

OR

try with as Ankur mentioned,

var approverName = current.approver.getDisplayValue();

 

If my response helps you resolve your issue. Kindly mark it as helpful & correct. It will be helpful to future readers! 👍🏻
Thanks,
Sagar Pagar

The world works with ServiceNow

Ankur Bawiskar
Tera Patron
Tera Patron

@avinashdubey103 

simply use this

var approverName = current.approver.getDisplayValue();

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader