Use PDIs? Take our 5-minute survey to help shape the PDI roadmap.

Email script for approval in service portal

Nicholas Hromya
Giga Guru

Hello all,

As an approver, I want to get an email that directs me to the Service Portal (not the ESC) to show me the details of a requested item to give approval or rejection.

 

I am not very good at scriptiing...

 

I did find the email script request_item_approval.  This seems to send approvers to the ESC.  My task is make this in the service portal as we have not introduced our teams to the ESC yet.

 

Thank you in advance.

Nick

1 ACCEPTED SOLUTION

 

The sys_id format appears valid, but please add the table parameter to the URL.

Change:

 
var approvalUrl =
    gs.getProperty('glide.servlet.uri') +
    'sp?id=approval&sys_id=' +
    encodeURIComponent(current.getUniqueValue());

to:

 

 
var approvalUrl =
    gs.getProperty('glide.servlet.uri') +
    'sp?id=approval&table=sysapproval_approver&sys_id=' +
    encodeURIComponent(current.getUniqueValue());

The generated URL should be:

 

 
https://<instance>/sp?id=approval
&table=sysapproval_approver
&sys_id=<approval_record_sys_id>

 

Use only one template.print() block. Remove this incomplete duplicate line:

 
template.print(
    '<div style="padding-bottom:32px"> ' +
    '<span style="margin-right: 4px;">View</span> ' +
    '<a href="' + approvalUrl + '"');

Use the complete section below:

 

 
var approvalId = current.getUniqueValue();

var approvalUrl =
    gs.getProperty('glide.servlet.uri') +
    'sp?id=approval&table=sysapproval_approver&sys_id=' +
    encodeURIComponent(approvalId);

var linkStyle =
    'color:#4F52BD;' +
    'font-size:16px;' +
    'line-height:24px;' +
    'font-family:Lato,Arial,sans-serif;' +
    'display:inline-block;';

template.print(
    '<div style="padding-bottom:32px;">' +
        '<span style="margin-right:4px;">View</span>' +
        '<a href="' + approvalUrl + '" ' +
            'style="' + linkStyle + '">' +
            gs.getMessage('approval request new') +
        '</a>' +
    '</div>');

Also confirm that the notification is configured on:

 
Approval [sysapproval_approver]

The current.getUniqueValue() value must be the sys_id of the individual approval record, not the RITM sys_id.

To validate it, copy the sys_id from the generated URL and open this as an administrator:

 

 
sysapproval_approver.do?sys_id=7dc03869476207142f667d88c26d4369
 

View solution in original post

16 REPLIES 16

@Nicholas Hromya 
That is great...let me know if you need more help or else if it works for you then please accept the solution so that the thread can be closed.

When I impersonate my approver, If I click on Approvals menu, and I click on this record,

the url goes to

servicenowservices.com/sp?id=approval&table=sysapproval_approver&sys_id=7dc03869476207142f667d88c26d4369

 

This is ideal, because this record shows the approval the details.