List of open approvals pending to each approver as a report

reddy8055
Tera Contributor

Hi,

I need help in creating email notification with list of pending approvals (state = requested) to each approver. (only 1 notification with all open approvals)

And need this report scheduled on weekly to each approver to show pending approvals in single list (change,  RITM, Knowledge etc..)

 

Thanks,

2 REPLIES 2

Simon Rudd
Tera Contributor

Hi Reddy,

 

I am no expert in scripting, so there may well be a better and more efficient way to do this, however to get you started this may help. It sends out a reminder to outstanding approvers for RITMs.

You need an event, a scheduled job that will generate the event, a mail script and a notification that will be sent out when the event is generated.

 

1. Create an event (in this case I have used 'approval.reminder')

 

-------------------------------

 

2. Create a scheduled job:

var arrUtil = new ArrayUtil(); //set up array to find all pending approvals for users
var answer = [];
var app = new GlideRecord('sysapproval_approver'); //set up variable to retrieve approvals that are pending
app.addQuery('state','requested'); //only retrieve approvals if they are pending (in requested state)
app.addQuery('sysapproval.sys_class_name','sc_req_item'); //only find approvals for ritm
//app.addQuery('sysapproval.document_id.sys_class_name', 'Requested Item');
app.addQuery('sys_created_on','<',gs.daysAgoStart(3)); //approvals are over 3 days old
app.orderBy('approver');
app.query(); //retrieve all approvals that meet our query
while(app.next()){ // step through the approvals one by one
if (arrUtil.indexOf(answer, app.approver.sys_id)==-1) { //if the approver is not currently in our list, add them (next line adds them)
answer.push(app.approver.sys_id);
}
}
for (var i = 0; i < answer.length; i++) { //have array that lists each user who has open change approvals We'll step through each
gs.eventQueue('approval.reminder', app, answer[i]); //and fire off the event for each user, passing their sys_id as parm1
}

 

-------------------------------

 

 

3. Mail script (approval_reminder)

var url = '<a href="' + gs.getProperty('glide.servlet.uri') + 'SSP?id=approvals' + '"> Click Here</a>';
//template.print(url);

var app = new GlideRecord('sysapproval_approver'); //create a query to retrieve open approvals
app.addQuery('state','requested'); //only retrieve approvals that are pending
app.addQuery('approver',event.parm1); //only find approvals for the current approver
app.addQuery('sys_created_on','<',gs.daysAgoStart(3)); //approvals are over 3 days old
app.addQuery('sysapproval.sys_class_name','sc_req_item'); //only find approvals for ritm
app.query();
while(app.next()){
//now that we have an approval for that user, we are going to look up the change tickets they need to approve and print out the data
var ritm = new GlideRecord('sc_req_item'); //find the first related ritm approval and print info
ritm.get(app.sysapproval);

template.print(ritm.number + ' - ' + ritm.short_description + ' - ' + ritm.sys_created_on + ' - ' + ritm.request.requested_for.getDisplayValue() + '</br>');
}

template.print('<br>' + url + ' to view these approvals');
template.print('<br>');

 

-------------------------------

 

4. In the notification, ensure that you add the following line: ${mail_script:approval_reminder}

 

Like I said, this may get you started and need some refining based in your requirements.

 

Simon Rudd
Tera Contributor

Alternatively, if the above is not what you are after, please see the below link:

https://community.servicenow.com/community?id=community_blog&sys_id=1fe969a71b9c1010fff162c4bd4bcb45