Approve/Reject button on change form
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2017 07:28 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2017 09:04 AM
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();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-12-2017 02:36 AM
Hi Justin,
Thank you !! . It is worked for me
Thanks & Regards,
Shravan Kumar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-12-2017 05:44 AM
Glad to help, Shravan!
Please mark my answer as correct if you feel it was. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2024 03:11 AM
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.