๐ Scenario-Based Question
ย
Use Case: Prevent Incident Submission Without Attachment
We want to make sure a user cannot submit an Incident unless at least one file ๐ is attached to the form.
๐ Steps to Implement:
- Create a Business Rule
- โ Active
- โ Advanced
- โ Before Insert
- ๐ Table:
incident
- Write the script and save:
(function executeRule(current, previous /*null when async*/) { var gr = new GlideRecord("sys_attachment"); gr.addQuery("table_sys_id", current.sys_id); gr.query(); if (!gr.hasNext()) { gs.addErrorMessage("๐ Attachment is required to submit this Request"); current.setAbortAction(true); } })(current, previous);
- Test: Try to submit a new Incident without an attachment. Youโll see an โ error message, and the record wonโt be created.
๐ก Pro Tip:
Instead of just blocking the submission, you can also guide users with a UI Policy to visually prompt them to attach a file before submission.