How to Run A business rule that will abort Insert action if no attachment found.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2020 07:25 AM
Good Morning,
I'm trying to create a business rule that checks for attachments on the sc_req_item table. The objective is to prevent Insert if no attachment is found Of one specific Item on the sec_req_item table. Is it possible to get this done? It seems the business rule would be querying two tables: sys_attachment and sc_req_item.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2020 07:38 AM
Hi,
I think it's possible, as you attach any document at any item a new entry in sys_attachment table it's created. You should create a BR for sc_req_item and query against sys_attachment, should be something similar as follows:
var grAttach = new GlideRecord('sys_attachment');
grAttach.addQuery('table_sys_id', current.sys_id);
grAttach.query();
if(grAttach.getRowCount() <= 0) {
current.setAbortAction(true);
}
If it was helpful, please give positive feedback.
Thanks,
☆ Community Rising Star 22, 23 & 24 ☆

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2020 07:49 AM
Hi meshia ,
Write a before business rule.
When: before insert
Conditions: !current.hasAttachments()
Script:
gs.addErrorMessage("No attachments");
current.setAbortAction(true);
mark my answer correct and helpful based on impact !
regrads,
apeksha