Make Additional Comments Mandatory when user click on the Reject Button
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2023 02:06 AM
Hi All,
I want to make comments mandatory while click on the reject Button. I have written script Comments are getting mandatory when clicking on the button But is not rejecting the request. Please help me on this .

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2023 02:18 AM
Hello @suresh40,
One option is to use a UI policy instead of a client script to make the comments field mandatory when rejecting the request. You can create a UI policy with the following conditions:
- Table: sysapproval_approver
- Field: comments
- Mandatory: true
- Reverse if false: true
- On load: false
- Condition: state=requested
This way, the comments field will only be mandatory when the state is requested, and the reject button will not disappear. You can also add a UI policy action to show a message to the user when they try to reject without comments. You can find more information about UI policies here.
Another option is to modify your client script to use g_form.submit instead of gsftSubmit. This will ensure that the form is submitted with the reject action and the comments are validated. You can also use g_form.addErrorMessage to display a message to the user when they try to reject without comments. Your script could look something like this:
function RejectButton() {
if (g_form.getValue(‘comments’) == “”) {
g_form.setMandatory(‘comments’, true);
g_form.addErrorMessage(‘Please enter comments before rejecting’);
return false;
} else {
g_form.submit(‘reject_action’);
}
}
You can find more information about g_form.submit here.
Kind Regards,
Swarnadeep Nandy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2023 02:20 AM
Hello @suresh40 ,
Making Additional Comments Mandatory when user click on the Reject Button is a part of client side script in the reject UI action.
Just check the condition if the addiditional commnets are empty and add an alert inside the loop alond with it return false someting like below:
Best Regards,
Nayan Dhamane
ServiceNow Community Rising Star 2023.