Approval Auto Rejection Script

Nikita50
Tera Expert

Per current setup all the requests are auto rejected with 8 days except for one group lets name is A.

Script is already in place of it.

New requirement is to set exception for three group, lets name them A,B,C

 

How to update existing script to add B, C also.

 

Current script:

var ca = new GlideRecord('sysapproval_approver');
ca.addQuery('state', 'requested');
ca.addQuery('sys_created_on', '<', gs.daysAgo(8));
    //Update: Adding condition 
var cancelOR = ca.addQuery('group.assignment_group.name', '!=', 'A');
cancelOR.addOrCondition('group', '');
1 ACCEPTED SOLUTION

SN_Learn
Kilo Patron
Kilo Patron

Hi @Nikita50 ,

 

Please replace the code as below and try

var ca = new GlideRecord('sysapproval_approver');
ca.addQuery('state', 'requested');
ca.addQuery('sys_created_on', '<', gs.daysAgo(8));
    //Update: Adding condition 
// **Update the below line to addEncodedQuery condition**
var cancelOR = ca.addQuery('group.assignment_group.name', '!=', 'A');
//Updated Query
var cancelOR = ca.addEncodedQuery("group.assignment_group.name!=AORgroup.assignment_group.name!=BORgroup.assignment_group.name!=C");
cancelOR.addOrCondition('group', '');

 

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

----------------------------------------------------------------
Mark this as Helpful / Accept the Solution if this helps.

View solution in original post

8 REPLIES 8

SN_Learn
Kilo Patron
Kilo Patron

Hi @Nikita50 ,

 

Please replace the code as below and try

var ca = new GlideRecord('sysapproval_approver');
ca.addQuery('state', 'requested');
ca.addQuery('sys_created_on', '<', gs.daysAgo(8));
    //Update: Adding condition 
// **Update the below line to addEncodedQuery condition**
var cancelOR = ca.addQuery('group.assignment_group.name', '!=', 'A');
//Updated Query
var cancelOR = ca.addEncodedQuery("group.assignment_group.name!=AORgroup.assignment_group.name!=BORgroup.assignment_group.name!=C");
cancelOR.addOrCondition('group', '');

 

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

----------------------------------------------------------------
Mark this as Helpful / Accept the Solution if this helps.

This is not working. Marked as correct by mistake.

Hi @Nikita50 ,

 

Did you try the below:

var ca = new GlideRecord('sysapproval_approver');
ca.addQuery('state', 'requested');
ca.addQuery('sys_created_on', '<', gs.daysAgo(8));
    //Update: Adding condition 
var cancelOR = ca.addEncodedQuery("group.assignment_group.name!=AORgroup.assignment_group.name!=BORgroup.assignment_group.name!=C");
cancelOR.addOrCondition('group', '');

 

Please let me know if this is not working and share the whole code.

----------------------------------------------------------------
Mark this as Helpful / Accept the Solution if this helps.

yes i did that

var cancelApprovals = new GlideRecord('sysapproval_approver');
cancelApprovals.addQuery('state', 'requested');
cancelApprovals.addQuery('sys_created_on', '<', gs.minutesAgo(2));
   

var cancelOR = cancelApprovals.addEncodedQuery("assignment_group.name!=A^ORassignment_group.name!=B^ORassignment_group.name!=C");
cancelOR.addOrCondition('group', '');
    //END Update
var caOR = cancelApprovals.addQuery('sysapproval.sys_class_name', 'sc_request');
caOR.addOrCondition('sysapproval.sys_class_name', 'sc_req_item');
caOR.addOrCondition('sysapproval.sys_class_name', 'sc_task');
cancelApprovals.query();
while(cancelApprovals.next()){
   cancelApprovals.state = 'rejected';
   cancelApprovals.comments = 'cancel.';
   cancelApprovals.update();
}