How to Remove Duplicate Attachments Created by Record Producer

Minamizono
Tera Contributor

I created a Service Portal page using a Record Producer and added an attachment field.
However, when the user clicks the Submit button, two attachment records are created.

Details:

  • One attachment is created when the user uploads the file on the portal.

  • Another attachment is created when the user submits the form and the record is generated.

  • As a result, duplicate entries are created in both sys_attachment and sys_attachment_doc.

I understand this is considered OOTB behavior, but I would like to keep only one attachment.

I considered implementing a Business Rule to delete the duplicate, but the only reliable identifier for detecting duplicate attachments is the hash value (sys_attachment.hash).
Therefore, I need to determine the hash first and then delete the older duplicate attachment when the record is submitted.

 

Given this behavior (two attachments being created),
how can I delete only one of the duplicate attachments at submission time?

Specifically:

  • Use the hash value to identify duplicate attachments
  • Delete the older one during the Record Producer submission
  • Keep only one attachment (the latest)

Do you have recommended approaches (Business Rule, Script Include, Workflow, etc.) to achieve this?

 

If you want, I can also prepare a complete, working Business Rule script matching this explanation.

1 REPLY 1

sunilsargam
Kilo Sage

Hi @Minamizono ,

 

Since the file name will be the same for the records, you can iterate on filename field on sys_attachment table also you can add a condition to check the tableSysID (which would be record sys_id)

 

thank you

Sunil Sargam