Creating a new record on attachment insert

kunal16
Tera Expert

Hi all, I have a requirement like this- I have got two tables - Table A and Table B My requirement - 1. If an attachment is attached to a record A001 in table A, then create a new record B001 in table B 2. Also, if the attachment is updated with a new one on record A001, then delete the old record B001 and create a new record B002 in table B How the above can be achieved?? Thanks advance!!

3 REPLIES 3

Chuck Tomasi
Tera Patron

Hi Kunal,



This is the role of an AFTER business rule. You can create a business rule on sys_attachment (not table a) to watch for updates, inserts, deletions, etc that include the source table A and take the appropriate action on table B...



Reference:


Business Rules - ServiceNow Wiki


Business Rules Best Practices - ServiceNow Wiki  


Ankur Bawiskar
Tera Patron
Tera Patron

Hi Kunal,



You will have to write a business rule on attachment table i.e. sys_attachment


Have an after insert business rule with following condition so that it runs only for your table



current.table_name == 'tableA'



Script



var gr = new GlideRecord('tableB');


gr.initialize();


gr.field1 = 'hello'; // have your fields here which you want to populate


gr.insert();



I don't think you can determine if attachment is updated or not. When you attach new attachment it creates new record in sys_attachment table


So the second functionality is somewhat not achievable



Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.


Thanks


Ankur


Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi,

Can you please help me with the code for a dynamic attachment in a notification?

Requirement is - User is selecting Request Type as Export Group Members and file should be sent to Requested For with the list of Group members in that particular group. 


File varies from group to group. Please help me with the code for this.

 

Thanks