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

I do have this

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

This sends me to 

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

 

This seems right, but I get 

Record not found.  😞

 

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
 

YES!  It worked.  I have to figure out the other print items.  But it is working now!  Thank you SO much!

I did have to impersonate the approver (which is good) to see the approval and reject buttons.  When I looked at it myself, I saw the record but I could not approve or reject.   Which is good!

Thanks again!

I am starting over and I will try to incoporate

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

 this var to the requestUrl 

 

I will remove the requestUrl and replace it with approvalUrl in the display and check

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

 

Thanks!