How to fire Business Rule with an attachment?

AndresGT1
Giga Expert

I'm using an 'After - Update' business rule that checks the name of an attachment.

The business rule works fine.

The problem is that if they attach the file, the business rule on update won't fire unless they change a value in the form.

How can I make the business rule to run every time they save the form?

8 REPLIES 8

Mike Allen
Mega Sage

Have you tried an onSubmit client script that has an AJAX call?   That should do it.


SanjivMeher
Kilo Patron
Kilo Patron

Hi Andres,



What are you doing in the business rule. Because when you attach a file to record, the record doesnt get saved. It creates a record is sys_attachment table. So you may want to write a business rule on sys_attachment table, depends on what is your usecase.



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

sanjivmeher


ursnani


I have created "After" BR on sys_attachment table. When an attachment is made on my custom table, the BR is getting triggered. What i m doing in that BR is i m updating the record of my custom table as below.. When i do an attachment on the record('e7ba6025130493c01174bee32244b025') its not updating the file name as expected in the below code



But when i open an another record with different sysid leaving the hardcoded sysid in the BR as it is, it updates the record for the hardcoded sysid.. For some reason, its not updating the currently opened record .. any suggestion



var testrec=new GlideRecord('x_opt_macro_govern_macros');


testrec.addQuery('sys_id','e7ba6025130493c01174bee32244b025');// for testing purpose, i hardcorded the sysid.


testrec.query();


while(testrec.next()){


testrec.file_name='482fc6cddb58934480bde1d3ca9619d6'; // for testing purpose, i hardcorded the sysid.


testrec.update();


}


function onAfter(current, previous) {


  //This function will be automatically called when this rule is processed.


str = current.file_name;


var Epos = str.search('Estimate Preview');



if(Epos != -1){        



var JocAttach = new GlideRecord(current.table_name);


JocAttach.addQuery('sys_id',current.table_sys_id);


JocAttach.query();


if(JocAttach.next()){


              JocAttach.file_name = 'give your name';


}


        }


}



After - Business rule on Attachment (sys_attachment) table.