Approve/Reject button on change form

shravan3
Kilo Expert

Hi,

Please let us know how to add Approve/Reject button on change form .These buttons should same like   buttons on Approval form that is the buttons should be visible only when the approver logins into the ServiceNow. These buttons should not be visible when other user logins into the ServiceNow.

Thanks & Regards,

Shravan Kumar

7 REPLIES 7

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


Hi Justin,



Thank you !! . It is worked for me



Thanks & Regards,


Shravan Kumar


Glad to help, Shravan!



Please mark my answer as correct if you feel it was. Thanks!


Hi @Justin Abbott ,
I am new to the ServiceNow developer, please let me know how we can write the same code from client script, we have a requirement this Approve/Reject buttons needs to displayed on the change form but only for service operation workspace(SOW), it accepts client script. Please find the below attached screenshot. I think script include is same, can you please let me know how can we access those from client side as per the below screenshot.

HemagiriB_0-1715854281164.png