diff --git a/Client-Side Components/Client Scripts/Prevent Rejection Without Comments/readme.md b/Client-Side Components/Client Scripts/Prevent Rejection Without Comments/readme.md new file mode 100644 index 0000000000..8476b55a5f --- /dev/null +++ b/Client-Side Components/Client Scripts/Prevent Rejection Without Comments/readme.md @@ -0,0 +1,72 @@ +🧩 Readme: Prevent Rejection Without Comments – Client Script +πŸ“˜ Overview + +This Client Script enforces that approvers must enter comments before rejecting a record in the Approval [sysapproval_approver] table. +It ensures accountability, audit readiness, and clear justification for rejection decisions. + +🧠 Use Case +Field Details +Table sysapproval_approver +Type Client Script – onSubmit +Purpose Prevent users from rejecting approvals without comments +Business Value Ensures transparency and proper audit trail in approval workflows +βš™οΈ Configuration Steps + +Navigate to System Definition β†’ Client Scripts. + +Click New. + +Fill the form as follows: + +Field Value +Name Prevent Rejection Without Comments +Table sysapproval_approver +UI Type All +Type onSubmit +Active βœ… +Applies on Update + +Paste the following script in the Script field. + +πŸ’» Script +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; +} + +πŸ§ͺ Example Scenario +Field Value +Approver John Doe +State Rejected +Comments (empty) + +User Action: Clicks Update +System Response: Shows error message β€” + +β€œPlease provide comments before rejecting the approval.” +Record submission is blocked until comments are provided. + +βœ… Expected Outcome +🚫 Prevents rejection without comments +⚠️ Displays user-friendly validation message +πŸ“ Ensures that every rejection has a reason logged for compliance + + diff --git a/Client-Side Components/Client Scripts/Prevent Rejection Without Comments/script.js b/Client-Side Components/Client Scripts/Prevent Rejection Without Comments/script.js new file mode 100644 index 0000000000..8661d77e41 --- /dev/null +++ b/Client-Side Components/Client Scripts/Prevent Rejection Without Comments/script.js @@ -0,0 +1,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; +}