forked from ServiceNowDevProgram/code-snippets
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
23 lines (18 loc) · 832 Bytes
/
script.js
File metadata and controls
23 lines (18 loc) · 832 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
//Prevent Rejection Without Comments
function onSubmit() {
// Get the current state value of the approval record
var state = g_form.getValue('state');
// Get the comments entered by the approver
var comments = g_form.getValue('comments');
// Check if the approver is trying to REJECT the record
// The out-of-box (OOB) value for rejection in sysapproval_approver is "rejected"
// If state is 'rejected' and comments are empty, stop the submission
if (state == 'rejected' && !comments) {
// Display an error message to the user
g_form.addErrorMessage('Please provide comments before rejecting the approval.');
// Prevent the form from being submitted (block save/update)
return false;
}
// Allow the form submission if validation passes
return true;
}