The CreatorCon Call for Content is officially open! Get started here.

Approval script

akin9
Tera Contributor

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();
}
}

13 REPLIES 13

Hi @Saurabh Gupta  ,

I have already checked, no executions on today.

 

akin9_0-1694409459418.png

 

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

Saurabh Gupta
Kilo Patron

let me check


Thanks and Regards,

Saurabh Gupta

Siva Jyothi M
Mega Sage

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.

SivaJyothiM_1-1694412417587.png

 

 

2.Create a notification like below.

SivaJyothiM_0-1694412178286.png

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.