After deleting the attachment its still stored into the sys_attachment table

Sovan
Tera Contributor

We have created a custom attachment field for our record producer. When user is going to create a record with an attachment, before submitting the record first they attach the attachment and then they deleted that and again they attached a new one. 

However that deleted attachment has been stored into the sys_attachment table with prefix ZZ_YY and the new attachment has been stored properly.

 

We need to remove that deleted attachment (prefix ZZ_YY) from the sys_attachment table while submitting the record with the new attachment.

Please help to solve this.

15 REPLIES 15

jaheerhattiwale
Mega Sage
Mega Sage

@Sovan Create a before insert business rule on "Attachment [sys_attachment]" table. 

Add filter condition "table name is YOUR TABLE NAME"

In script check if the ZZ_YY prefixed record with same table_sys_id is present. If present then delete it.

 

Please mark as correct answer if this solves your issue.

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

Sovan
Tera Contributor

Hi,

 

As per your solution I tried to create BR but we are getting the best practice warning as "Before Business Rules should not modify records on other tables".

 

@Sovan You can change the type to after.

 

Please mark as correct answer if this solves your issue.

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

Sovan
Tera Contributor

No, its not working as expected. This is not deleting the attachment after the record inserted.