The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Adding "approve" and "reject" buttons to Group Approvals (GAPRV) requests

mattystern
Kilo Sage

Hello,

I am trying to add an "Approve" and "Reject" button to group approval requests. I found this thread on adding a change button to the CHG form and implemented it, but I was unable to edit the code to display onto GAPRV requests. I took the original code and changed "sysapproval_approver" to "sysapproval_group." 

First, I edited this into the changeUtils script include:

canApprove: function(id) {


         var canApprove = false;



         if (id) {


                   var gr = new GlideRecord('sysapproval_group');


                   gr.addQuery('sysapproval', id);


                   gr.addQuery('state', 'requested');


                   gr.query();


                   while (gr.next()) {


                             if (isApprovalMine(gr)) {


                                       canApprove = true;


                             }


                   }


         }



         return canApprove;


},

	type: 'ChangeUtils'
});

 And I then made two Approval UI actions, one for approve and another for reject. Here is my "reject" button's code:

Condition: new ChangeUtils().canApprove(current.sys_id)

function rejectChg() {


         var gr = new GlideRecord('sysapproval_group');


         gr.addQuery('state', 'requested');


         gr.addQuery('sysapproval', current.sys_id);


         gr.query();


         while (gr.next()) {


                   if (isApprovalMine(gr)) {


                             gr.setValue('state', 'rejected');


                             gr.update();


                   }


         }


         action.setRedirectURL(current);


}



rejectChg();

Neither of the buttons display on the form, so I believe the condition is not being met. I have them both set to be form buttons. Specifically, I think line: gr.addquerry("sysapproval", id) may be the culprit here, although I am unsure.

Any help is appreciated!

-Matt

1 ACCEPTED SOLUTION

mattystern
Kilo Sage

I finished this in a different way. I just made two UI Actions, one for Approve and one for Rejection. My condition for them was this, so the buttons don't show up on group approvals which are already "approved" or "rejected":

current.approval != "approved" && current.approval != "rejected"

And my script was as follows, just filtering to find the request by number and then updating the state and the approval_user fields. The "reject" one was identical minus the work "rejected": 

current.approval = "approved";


var ap = new GlideRecord('sysapproval_group');
ap.addQuery('number', current.number);
ap.query();


while(ap.next()){
 ap.state = 'approved';
 ap.approval_user = gs.getUserID(); 
 ap.update();
}

current.update();

 

View solution in original post

1 REPLY 1

mattystern
Kilo Sage

I finished this in a different way. I just made two UI Actions, one for Approve and one for Rejection. My condition for them was this, so the buttons don't show up on group approvals which are already "approved" or "rejected":

current.approval != "approved" && current.approval != "rejected"

And my script was as follows, just filtering to find the request by number and then updating the state and the approval_user fields. The "reject" one was identical minus the work "rejected": 

current.approval = "approved";


var ap = new GlideRecord('sysapproval_group');
ap.addQuery('number', current.number);
ap.query();


while(ap.next()){
 ap.state = 'approved';
 ap.approval_user = gs.getUserID(); 
 ap.update();
}

current.update();