Can't query for current in sys_attachment table after inserting request item

andreea4
Kilo Explorer

I have a form where the user is able to attache documents. After pressing submit, I'm trying to get the attachments so I've created a business rule "Running after insert" for sc_req_item table.

I'm trying to see if I can find the attachment but i'm not able to find the current one. If I'm looking for an older attachment it works perfectly.  I guess that when I'm trying to find the current.sys_id is not already created in the table. But is there a way to find it?

 

(function executeRule(current, previous /*null when async*/) {
 

var gr = new GlideRecord('sys_attachment');
gr.addQuery('table_sys_id', current.sys_id);
gr.addQuery('table_name', current.getTableName());
gr.query();


if (gr.next()){
gs.info(' record FOUND');
}
else{
gs.info(' record not found');
}


})(current, previous);

1 ACCEPTED SOLUTION

SanjivMeher
Kilo Patron
Kilo Patron

Why do you want to check the attachment? What happens, if you make the business rule async?


Please mark this response as correct or helpful if it assisted you with your question.

View solution in original post

2 REPLIES 2

SanjivMeher
Kilo Patron
Kilo Patron

Why do you want to check the attachment? What happens, if you make the business rule async?


Please mark this response as correct or helpful if it assisted you with your question.

Hi Sanjiv. It worked after I made the business rule async. Thanks for your answer!