How to Run A business rule that will abort Insert action if no attachment found.

Meshia
Kilo Guru

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.

2 REPLIES 2

Adrian Ubeda
Mega Sage
Mega Sage

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, 

If it was helpful, please give positive feedback! ✔
☆ Community Rising Star 22, 23 & 24 ☆

Apeksha Joshi
Kilo Guru

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