Justin Abbott
Giga Guru

First, add a new method to the ChangeUtils Script Include.



canApprove: function(id) {


        var canApprove = false;



        if (id) {


                  var gr = new GlideRecord('sysapproval_approver');


                  gr.addQuery('sysapproval', id);


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


                  gr.query();


                  while (gr.next()) {


                            if (isApprovalMine(gr)) {


                                      canApprove = true;


                            }


                  }


        }



        return canApprove;


},



Then create a new Approve UI Action on the change_request table.



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



Script:



function approveChg() {


        var gr = new GlideRecord('sysapproval_approver');


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


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


        gr.query();


        while (gr.next()) {


                  if (isApprovalMine(gr)) {


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


                            gr.update();


                  }


        }


        action.setRedirectURL(current);


}



approveChg();



and a new Reject UI Action on the change_request table.



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



Script:



function rejectChg() {


        var gr = new GlideRecord('sysapproval_approver');


        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();