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

Schedule job to cancel RITM if approval is pending with Inactive approver

Geeta5
Giga Contributor

Hi All,

I have a requirement where I have to create a job which runs daily to check all such approvals which are pending with inactive approvers. Below condition should be checked:

1)Approval is in 'requested' state and is pending with Inactive user

2)This is the only approval triggered in the RITM. This should not be a part of group approval.

3)In case this is the only User approval triggered in the RITM, then this approval should be set as 'Cancelled' and the corresponding RITM also set as 'Closed Incomplete'. User should get a notification that request has been 'Closed incomplete' as approver is no longer in system, please raise new request.

Please help on this 

 

--

Thanks,

Geeta Dhami

15 REPLIES 15

Hi Geeta,

I forgot to use addQuery(); updated script now; please check

var approvalAgg = new GlideAggregate('sysapproval_approver');

approvalAgg.addEncodedQuery('approver.active=false^state=requested^groupISEMPTY');

approvalAgg.addAggregate('COUNT','sysapproval');

approvalAgg.query();

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Ankur,

 

I tried adding that line also but still count is returning 'Undefined'.

I am using below code to test for 1 RITM:

 

find_real_file.png

Hi Geeta,

So you are saying it is going inside while but printing undefined for line 15?

also please convert gs.log to gs.info

Can you add row Count after line 11

gs.info('Row Count is: ' + approvalAgg.getRowCount());

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Ankur,

I have modified the code as below to get these things and testing for scenario where a RITM has two user approvals in requested state(one with inactive user and other with active user)

1)To get a RITM where approver is inactive. Once this is checked the code will move inside while loop(line 11).

It is going inside that (Correct)

Now I have to check if for this RITM there is only 1 approval triggered.

Again I have done Glide Record and pass that RITM and other condition.Line no 19 is to get the count.

Here for the sample RITM i have two rows which are requested for approval(1 to inactive user  and other to inactive user)

Line no 21 should give me count value as 2, but it is giving me count as 1.

Please suggest, where I am going wrong.

 

find_real_file.png

Hi Geeta,

you should update it as below

var count_gr = new GlideRecord('sysapproval_approver');

count_gr.addEncodedQuery('state=requested^groupISEMPTY');

count_gr.query();

var count = count_gr.getRowCount();

gs.info('Hi' + count);

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader