How to make attachment Mandatory for Approval in sysapproval_approver
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi,
How to make attachment mandatory approval table .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hey @armanoj
You can enforce this using a Before Update Business Rule on the sysapproval_approver table. Before allowing the approval, check whether an attachment exists for the current approval record in the sys_attachment table. If no attachment is found, abort the update and display an error message.
(function executeRule(current, previous) {
if (current.state.changesTo('approved')) {
var att = new GlideRecord('sys_attachment');
att.addQuery('table_name', current.getTableName());
att.addQuery('table_sys_id', current.sys_id);
att.query();
if (!att.hasNext()) {
gs.addErrorMessage('Please attach a document before approving the record.');
current.setAbortAction(true);
}
}
})(current, previous);If you also want to make attachments mandatory when the approval is Rejected, include:
current.state.changesTo('approved') || current.state.changesTo('rejected')in the condition.
This server-side approach is recommended since it works regardless of whether the approval is updated from the UI, Flow Designer, or an API.
***********************************************************************************************************************************
If this response helps, please mark it as Accept as Solution and Helpful.
Doing so helps others in the community and encourages me to keep contributing.
Regards
Vaishali Singh
Servicenow Developer
Linkedin - https://www.linkedin.com/in/vaishali-singh-2273361bb
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
in this I'm getting another error also "Invalid value on Update"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hey @armanoj
The "Invalid value on Update" message is likely not caused by the attachment validation itself. current.setAbortAction(true) stops the update, but if the approval state is being changed through the OOB Approve/Reject UI Action or another Business Rule/Data Policy, the platform may also throw this generic error.
To troubleshoot:
- Temporarily disable the attachment validation and verify whether the approval updates successfully.
- Check for any other Business Rules, Data Policies, ACLs, or UI Actions on sysapproval_approver that might also be aborting the transaction.
- Review the system logs (System Logs > All) for the actual server-side exception.
If the only goal is to require an attachment before approval, the following validation is sufficient:
var att = new GlideRecord('sys_attachment');
att.addQuery('table_name', current.getTableName());
att.addQuery('table_sys_id', current.sys_id);
att.query();
if (!att.hasNext()) {
gs.addErrorMessage('Please attach a document before approving the record.');
current.setAbortAction(true);
}If you're seeing both "Please attach a document..." and "Invalid value on Update", then another validation is almost certainly running in parallel. Can you confirm whether you're approving the record from the Approval form, Related List, Workspace, or Email Approval? That will help identify the source of the second error.
********************************************************************************************************************
If this response helps, please mark it as Accept as Solution and Helpful.
Doing so helps others in the community and encourages me to keep contributing.
Regards
Vaishali Singh
Servicenow Developer
Linkedin - https://www.linkedin.com/in/vaishali-singh-2273361bb
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a week ago
hey @armanoj
Hope you are doing well.
Did my previous reply answer your question?
If it was helpful, please mark it as correct ✓ and close the thread . This will help other readers find the solution more easily.
Thankyou & Regards
Vaishali Singh
Servicenow Developer
Linkedin - https://www.linkedin.com/in/vaishali-singh-2273361bb