Approval issue

geogeorge
Tera Expert

Hi All,

 

We're implementing group approval for RITM using UI actions, where if any member of the group approves, the approvals to other users should be marked as "not required." However, it seems this isn't functioning correctly. What changes do I need to make in the code to achieve this? It's already set the wait condition to "Anyone to approve."

if (group) {
    var grApprovalGroup = new GlideRecord('sysapproval_group');
    grApprovalGroup.initialize();
    grApprovalGroup.assignment_group = group;
    grApprovalGroup.source_table = current.getTableName();
	grApprovalGroup.comments = current.variables.additional_comments;
    grApprovalGroup.parent = current.sys_id;
    grApprovalGroup.approval = 'requested';
    grApprovalGroup.insert();
}

 

6 REPLIES 6

Ankur Bawiskar
Tera Patron
Tera Patron

@geogeorge 

your above script is inserting the approvals.

You will have to write after update BR on approval table and check if any 1 person approves then mark others as Not required

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

@geogeorge 

something like this in after update BR on sysapproval_group

AnkurBawiskar_0-1737617767097.png

 

(function executeRule(current, previous /*null when async*/ ) {

    // Add your code here
    var gr = new GlideRecord("sysapproval_approver");
    gr.addQuery("group", current.getUniqueValue());
    gr.addQuery("sysapproval", current.parent);
    gr.addEncodedQuery('state!=approved'); // exclude the record which got approved
    gr.query();
    while (gr.next()) {
        gr.state = 'not_required';
        gr.update();
    }

})(current, previous);

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

@geogeorge 

if this is required only for Change Request then add this condition in BR condition

current.parent.sys_class_name == 'change_request'

 

AnkurBawiskar_1-1737617998405.png

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

@geogeorge 

Thank you for marking my response as helpful.

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