Triggering an Event from Scheduled Job that cancels approvals after 4 weeks.

EricG
Kilo Sage

Hello Guru's:

 

I've always struggled getting Events to trigger Email Notifications.  I'm hoping someone can advise why this isn't sending the email.

 

Use Case:

I need to send out a Notification to the Requestor when their catalog item is cancelled due to inactivity on the Approval Record. 

 

I have a Scheduled Job that combs the sysapproval_approver record for any "Reuested" state that is older than 4 weeks old.  (scheduled Job)

The code for the "Raise Event" is gs.eventQueue('sc_req_item.approval.cancelled', current, par1, par2);

The event raised is populating correctly. I get the User sys_id and Name in correct place.

EricG_0-1695820020930.png

 

I'm not able to to get the Notification to sent.

I've tried several ways to get this.

1. Used the event.  Nada

2. Set the notification to Insert/Update condition approval state is No Required and Approving state is Closed incomplete.

 

What might the issue be?

 

1 ACCEPTED SOLUTION

OlaN
Giga Sage
Giga Sage

Hi,

There is also a No-code way to solve this, by creating a Flow that does all the steps.

Providing a simple example below, you can use either the Send Notification (step 4 in my example), or the Send Email action (step 5 in my example).

Let me know if you want to dive into this, or require more help.

flow-cancel-old-approvals-and-send-notification.png

View solution in original post

7 REPLIES 7

AnveshKumar M
Tera Sage
Tera Sage

Hi @EricG 

Can you help me with the following queries?

 

  1. What is the table on which the notification is configured?
  2. You are passing the current as the Glide Object [gs.eventQueue('sc_req_item.approval.cancelled', current, par1, par2);]. This current refers to the Scheduled Job record, you can cross check the sys_id displayed is the sys_id of the scheduled job. You should pass the GlideRecord Object (if the notification is configured for sc_req_item table it should be the Glide Record object of RITM, if the notification is configured for sysapproval_approver table it should be the Glide Record object of Approval record.

Please try modifying the event triggering accordingly and check.

 

Please mark my answer helpful and accept as solution 👍✔️

Thanks,
Anvesh

The table is sysapproval_approver.  Currently.  

What I'm now passing, as i found out, is "eventname, "sysapproval_approver" , user sysid, user name"

 

As i reviewed my event logs, I saw the table wasn't being populated, so i hard coded it in the gs.eventqueue.

Is that what your asking.

Hi @EricG ,

Can you move the eventQueue line to the while block like the one below and try.

 

var par1 = '';
var par2 = '';
var gr = new GlideRecord("sysapproval_approver");
gr.addQuery('sysapproval.sys_class_name', 'sc_req_item'); //since all the approvals are generated only for RITMS
gr.addQuery('state', 'requested');
gr.addQuery('sys_created_on','<',gs.daysAgo(30));
//gr.addEncodedQuery("sys_created_on<=javascript&colon;gs.dateGenerate('2022-12-07','11:27:23')");
gr.query();

while (gr.next()) {
var num = gr.sysapproval.number;
par1 = gr.approver;
par2 = gr.approver.name;
gr.state = 'not_required'; // set approval state to No longer required
cancelKids(num); // cancel the RITMS
gr.setWorkflow(false); // deactivate all the BR which are running
gr.update();
gs.eventQueue('sc_req_item.approval.cancelled', gr, par1, par2);


}

function cancelKids(n) {
var children = new GlideRecord('sc_req_item');
children.addQuery('number', n);
children.query();

while (children.next())
if (children.stage != 'Complete') {
gs.log(" Request item Number " + gr.sysapproval.number + " has been canceled ");
var id = children.request; // store the sys_id of REQ which is related to RITM
children.stage = 'Request Cancelled';
children.u_close_code = "Not Solved (Other)";
children.close_notes = "Ticket has been canceled due to approval inactivity. If the items is still required, please submit a new ticket.";
children.closed_at = gs.nowDateTime();
children.closed_by = "6816f79cc0a8016401c5a33be04be441";
children.active = false;
children.state = '4'; // set RITM state to closed incomplete
cancelParent(id); // this will cancel the REQ associated with the corresponding RITM
children.setWorkflow(false);
children.update();
}
}

function cancelParent(id) {

var scReq = new GlideRecord("sc_request");
scReq.addQuery('sys_id', id);
scReq.query();

if (scReq.next()) {
scReq.state = '4';
scReq.stage = 'closed_incomplete';
scReq.active = false;
scReq.request_state = 'closed_cancelled'; // set REQ TO cancelled when all the RITMS are cancelled
scReq.setWorkflow(false);
scReq.update();
}
}

 

 

 

Thanks,
Anvesh

Followed this and still not Email.