Skip to content

Commit d9e42aa

Browse files
authored
Prevent Rejection Without Comments (#2650)
* Code for Moveworks bot messages for Flow to include url links * Delete Moveworks messages html for Flow * Create script.js * Create readme.md * Create script.js * Create readme.md * Delete Client-Side Components/Client Scripts/Auto Priority Update based on Impact and Urgency/readme.md * Delete Client-Side Components/Client Scripts/Auto Priority Update based on Impact and Urgency/script.js
1 parent 8eaa2ab commit d9e42aa

File tree

2 files changed

+95
-0
lines changed
  • Client-Side Components/Client Scripts/Prevent Rejection Without Comments

2 files changed

+95
-0
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
🧩 Readme: Prevent Rejection Without Comments – Client Script
2+
📘 Overview
3+
4+
This Client Script enforces that approvers must enter comments before rejecting a record in the Approval [sysapproval_approver] table.
5+
It ensures accountability, audit readiness, and clear justification for rejection decisions.
6+
7+
🧠 Use Case
8+
Field Details
9+
Table sysapproval_approver
10+
Type Client Script – onSubmit
11+
Purpose Prevent users from rejecting approvals without comments
12+
Business Value Ensures transparency and proper audit trail in approval workflows
13+
⚙️ Configuration Steps
14+
15+
Navigate to System Definition → Client Scripts.
16+
17+
Click New.
18+
19+
Fill the form as follows:
20+
21+
Field Value
22+
Name Prevent Rejection Without Comments
23+
Table sysapproval_approver
24+
UI Type All
25+
Type onSubmit
26+
Active ✅
27+
Applies on Update
28+
29+
Paste the following script in the Script field.
30+
31+
💻 Script
32+
function onSubmit() {
33+
// Get the current state value of the approval record
34+
var state = g_form.getValue('state');
35+
36+
// Get the comments entered by the approver
37+
var comments = g_form.getValue('comments');
38+
39+
// Check if the approver is trying to REJECT the record
40+
// The out-of-box (OOB) value for rejection in sysapproval_approver is "rejected"
41+
// If state is 'rejected' and comments are empty, stop the submission
42+
if (state == 'rejected' && !comments) {
43+
44+
// Display an error message to the user
45+
g_form.addErrorMessage('Please provide comments before rejecting the approval.');
46+
47+
// Prevent the form from being submitted (block save/update)
48+
return false;
49+
}
50+
51+
// Allow the form submission if validation passes
52+
return true;
53+
}
54+
55+
🧪 Example Scenario
56+
Field Value
57+
Approver John Doe
58+
State Rejected
59+
Comments (empty)
60+
61+
User Action: Clicks Update
62+
System Response: Shows error message —
63+
64+
“Please provide comments before rejecting the approval.”
65+
Record submission is blocked until comments are provided.
66+
67+
✅ Expected Outcome
68+
🚫 Prevents rejection without comments
69+
⚠️ Displays user-friendly validation message
70+
📝 Ensures that every rejection has a reason logged for compliance
71+
72+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//Prevent Rejection Without Comments
2+
function onSubmit() {
3+
// Get the current state value of the approval record
4+
var state = g_form.getValue('state');
5+
6+
// Get the comments entered by the approver
7+
var comments = g_form.getValue('comments');
8+
9+
// Check if the approver is trying to REJECT the record
10+
// The out-of-box (OOB) value for rejection in sysapproval_approver is "rejected"
11+
// If state is 'rejected' and comments are empty, stop the submission
12+
if (state == 'rejected' && !comments) {
13+
14+
// Display an error message to the user
15+
g_form.addErrorMessage('Please provide comments before rejecting the approval.');
16+
17+
// Prevent the form from being submitted (block save/update)
18+
return false;
19+
}
20+
21+
// Allow the form submission if validation passes
22+
return true;
23+
}

0 commit comments

Comments
 (0)