- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-25-2019 11:03 AM
Good Afternoon SNC,
I'm creating an "approval process" where reminder emails get sent out on a weekly basis, and if no approval is obtained after a month, the request gets cancelled and an email notification is sent to the requester advising them of the cancellation, and who the approver(s) of the ticket were so they can reach out to the approver(s) to discuss the request.
This works just fine for a catalog item that has a single approver, however if there are multiple approvers on a RITM, then the requester will end up with multiple "Cancellation notification" emails, 1-per approver on the request.
My goal here is to create an array in an email script so I can parse the sysapproval_approver table, and when the query finds 2 records with the same sysapproval field, it takes the value in the approver field on each ticket and creates an array. From there, the array would be printed using the email script to the notification... With this way, if there is 1 approver or if there's 10, the array will output the list of approvers in the email and send just 1 email with all the approvers.
My javascript is a little rusty and I'm struggling to get this coded out. Any ideas or can anyone take a stab at this and share their results? I don't think this is too crazy of an ask. Let me know what you think.
Thanks in advance!
Dan R
Solved! Go to Solution.
- Labels:
-
Request Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2019 02:03 PM
I was able to resolve the issue by making a substitution in your formula. the working script for me is:
var currentApprovalFor = current.sysapproval; // This is the line I added to assign the sysid of the "Approval for" field on the sysapproval_approver record to a variable
var appList=[]; // The array which will hold the approver list
var app = new GlideRecord('sysapproval_approver');
app.addQuery('sysapproval',currentApprovalFor); // I updated the 2nd parameter of this addQuery to look for all tickets with the sysapproval field = the current sysapproval_approver record
app.addQuery('state','requested');
app.query();
while (app.next())
{
appList.push(app.approver.getDisplayValue());
}
template.print('<font size="2" color="#808080" face="helvetica"><b>Approver(s):</b></font>');
template.print(appList);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-25-2019 11:14 AM
You can do something like this
var appList=[]; // The array which will hold the approver list
var app = new GlideRecord('sysapproval_approver');
app.addQuery('sysapproval',<requestid>);
app.addQuery('state','requested');
app.query();
while (app.next())
{
appList.push(app.approver.getDisplayValue());
}
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2019 10:01 AM
Thanks Sanjiv, this looks swell! Just 1 question:
could you explain line 3 of your code with the app.addQuery ('sysapproval',<requestid>); ?
I would understand this as saying query the sysapproval_approver table where sysapproval = <requestid>... but where is <requestid> being pulled from?
I'm just slightly confused on how the requestid is defined, is this a system variable that recognizes which ticket and sysid for the tickets in the table, or is <requestid> somehow denoted elsewhere and I need to ensure I'm pulling the correct field in?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2019 10:16 AM
request id is the RITM id. So basically you have to query the RITM table for all the RITM in Pending approval state.
For ex
var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('state','<approval state value>');
ritm.query();
while (ritm.next())
{
var appList=[]; // The array which will hold the approver list
var app = new GlideRecord('sysapproval_approver');
app.addQuery('sysapproval',ritm.getValue('sys_id'));
app.addQuery('state','requested');
app.query();
while (app.next())
{
appList.push(app.approver.getDisplayValue());
}
gs.eventQueue('event name',ritm,appList);// Trigger email using event and pass the approver list
}
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2019 07:04 AM
Thanks Sanjiv. Would this script work from an email notification script? I have a separate scheduled job that is kicking off the notification and I wanted to use an email script to inject the list of approvers. When I tried your script it did not give me the results I was expecting.