|
| 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 | + |
0 commit comments