Approval script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2023 10:09 PM
Hello Experts,
We want to create a reminder email notification for pending approval "SC_REQ_ITEM".
Requirement
1.want to give a reminder email every 7 days till 60 days from created.If any RITM is pending for approval.
2. if above conditions are met "Request - Reminder" notification needs to be sent
how to add the notification on the script?
we have tried below script using scheduled job but not working .
or else can we achieve any other ways?. kindly support.
var ritm = new GlideRecord('sc_req_item');
var encQuery = 'active=true^state=1'; //1 is state pending approval;
ritm.addEncodedQuery(encQuery);
ritm.query();
while (ritm.next()) {
var chkApprvl = new GlideRecord('sysapproval_approver');
chkApprvl.addQuery('document_id', ritm.sys_id);//find the approval related to this item
chkApprvl.addQuery('state', 'requested');//its state should be requested
chkApprvl.addQuery('sysapproval.sys_class_name','sc_req_item');
chkApprvl.addQuery('sys_updated_onRELATIVELE@dayofweek@ago@7'); //this checks if the approval has not be updated for 7 days
chkApprvl.query();
while(chkApprvl.next()) {
ritm.work_notes = 'Reminder email to approver sent after 7 days.';
ritm.update();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2023 10:17 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2023 10:41 PM
Hi,
In the trigger condition please remove the create relative condition and adjust the first notification in wait for duration.
Thanks and Regards,
Saurabh Gupta
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2023 10:21 PM
let me check
Thanks and Regards,
Saurabh Gupta
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2023 11:09 PM
Hi @akin9,
You need to create a Event, Notification and also a schedule job to trigger the notification based on the days.
Below is the example.
1. Register a Event.
2.Create a notification like below.
3.Schedule Job - Sample script which triggers the event for 7 days, 14 days and 21 days.
var gr = new GlideRecord('sysapproval_approver');
gr.addEncodedQuery("state=requested^sys_updated_onRELATIVELE@dayofweek@ago@7^sys_updated_onRELATIVEGT@dayofweek@ago@8");
gr.orderBy('sysapproval');
gr.query();
var reqForNum = '';
var newreqForNum;
while (gr.next()) {
newreqForNum = gr.sysapproval.number;
if (reqForNum != newreqForNum)
gs.eventQueue("approval.reminder", gr, gr.sysapproval.u_requested_for);
reqForNum = gr.sysapproval.number;
}
var gr2 = new GlideRecord('sysapproval_approver'); gr2.addEncodedQuery("state=requested^sys_updated_onRELATIVELE@dayofweek@ago@14^sys_updated_onRELATIVEGT@dayofweek@ago@15");
gr2.orderBy('sysapproval');
gr2.query();
while (gr2.next()) {
newreqForNum = gr2.sysapproval.number;
if (reqForNum != newreqForNum)
gs.eventQueue("approval.reminder14days", gr2, gr2.sysapproval.u_requested_for);
reqForNum = gr2.sysapproval.number;
}
var gr3 = new GlideRecord('sysapproval_approver');
gr3.addEncodedQuery("state=requested^sys_updated_onRELATIVELE@dayofweek@ago@21^sys_updated_onRELATIVEGT@dayofweek@ago@22");
gr3.orderBy('sysapproval');
gr3.query();
while (gr3.next()) {
newreqForNum = gr3.sysapproval.number;
if (reqForNum != newreqForNum)
gs.eventQueue("approval.reminder21days", gr3, gr3.sysapproval.u_requested_for);
reqForNum = gr3.sysapproval.number;
}
Mark this answer as correct and helpful if it solves your issue.
Regards,
Siva Jyothi M.