gliderecord for record created second before

Hafsa1
Mega Sage

I have this BR which I'm running whenever record in "approved", so that other group approvals get "no longer required".

But , just after 1st group approval , it triggers another approval and they are getting "no longer required" too just after creation.

 

Can we modify this code such that it should query only those approval record which are genereted 5 sec before current time?

As I have seen approval record are generated within 1 or 2 secs after 1st approval record is approved.

 
function renderTaskApprovalsMoot() {
        var gr = new GlideRecord('sysapproval_approver');
        gr.addQuery('sysapproval', current.sysapproval);
        var qc = gr.addQuery('state', 'requested');
        qc.addOrCondition('state', 'not requested');
        gr.query();
        while (gr.next()) {
            gr.state = 'not_required';
            gr.update();
        }
8 REPLIES 8

DrewW
Mega Sage
Mega Sage

It sounds like you do not have your group approval setup correctly.  If you set the group approval to approve or reject on the first response the other approvals should automatically be marked as no longer required.

Hafsa1
Mega Sage

we are creating approvals via BR. multiple approval record created in 1st level approval. If any one approves then 2nd level approval triggers to particular group. In 1st level approval, if anyone approves, then rest other are not becoming "no longer required"

Ankur Bawiskar
Tera Patron
Tera Patron

@Hafsa1 

you should differentiate it using the group field which will tell you the approval record is for which group

I added 1 more addQuery()

function renderTaskApprovalsMoot() {
        var gr = new GlideRecord('sysapproval_approver');
        gr.addQuery('sysapproval', current.sysapproval);
        gr.addQuery('group', current.group); // this will search only the records for this group approval
        var qc = gr.addQuery('state', 'requested');
        qc.addOrCondition('state', 'not requested');
        gr.query();
        while (gr.next()) {
            gr.state = 'not_required';
            gr.update();
        }

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Ankur Bawiskar
Tera Patron
Tera Patron

@Hafsa1 

ideally this should happen OOB if you set approval rule as Anyone 1 person approves

how have you configured the group approval? share screenshots.

If my response helped please mark it correct and close the thread so that it benefits future readers.

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