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

KPNow
Kilo Guru

It is completely understandable to want to avoid sending users to the Employee Center (ESC) if your organization hasn't rolled it out yet. By default, many baseline ServiceNow approval notifications point straight to ESC or the standard platform layout because of how their underlying email scripts construct URLs. To fix this without needing to write complex code from scratch, you can modify or replace the link target inside your email script to explicitly direct approvers to your standard Service Portal (sp) page instead.

To make this happen, navigate to System Notification > Email Scripts in your filter navigator, search for the request_item_approval script (or the specific email script referenced in your approval notification), and update its target URL logic. You can swap out the portal suffix in the script so that instead of generating an ESC link, it builds a clean link pointing to your standard portal view (for example, using sp?id=approval&sys_id= followed by the record's sys_id). Once you save that minor adjustment, any future approval emails will safely route your approvers right into the standard Service Portal environment they are already familiar with.

This sounds great, but I don't understand how 

sp?id=approval&sys_id= followed by the record's sys_id

will work.

 

For example, how do I get or find the record's sys_id in the email script?

Nicholas Hromya
Giga Guru

Looking over the mail script request_item_approval.

 

I am sure it is in here somewhere: 

This seems to show I need to change the  portalSuffix, but I am not sure to what.

 
    var requestItemId = current.sysapproval;
    var portalSuffix = new sn_ex_emp_fd.FoundationNotificationUtil().getPortalSuffix();
    var requestUrl = portalSuffix + '?id=ticket&table=sc_req_item&sys_id=' + requestItemId;
    var colorTheme = 'color: #4F52BD;';
    var fontSize = 'font-size: 16px;';
    var lineHeight = 'line-height: 24px;';
    var fontFamily = 'font-family: Lato, Arial, sans-serif;';
    var display = 'display: inline-block;';
    template.print('<div style="padding-bottom:32px"> <span style="margin-right: 4px;">View</span> <a href="' + requestUrl + '"');
    template.print('style="' + colorTheme + fontSize + fontFamily + display);
    template.print('">');
    template.print(gs.getMessage('approval request'));
    template.print('</a></div>');

 

Nicholas Hromya
Giga Guru

 

I tried adding the 

sp?id=approval&sys_id=

to the to the portalSuffix. 
That didn't work.  

I got a "Record not found" when I click the link from my email logs.

I went to the url

<instance name>

/sp?id=approval&sys_id=%3Fid%3Dticket&sys_id=712e3899476e03142f667d88c26d438d&table=sc_req_item

  // var portalSuffix = new sn_ex_emp_fd.FoundationNotificationUtil().getPortalSuffix();
   var portalSuffix = 'sp?id=approval&sys_id=';
   //