Attachment from record producer attachment variable not getting attached to the backend record

Swapnil Srivas1
Tera Contributor

Hi Experts,
I have a Record Producer on a custom table with an attachment variable which is not mapped to any backend field on the target table. I need that whenever an attachment comes from that attachment variable from record producer, it should be attached to the backend record. It is not happening because on the 'sys_attachment' table, the attachment record is created with table name having prefix 'ZZ_YY'. I am trying to remove that prefix using the script below but it is not updating it.

SwapnilSrivas1_0-1769082442091.png

Its an after insert business rule applied to the target table. I have given cross scope permission to write on 'sys_attachment' table.

4 REPLIES 4

Chaitanya ILCR
Mega Patron

Hi @Swapnil Srivas1 ,

1. try copying the attachment  

https://www.servicenow.com/community/developer-blog/servicenow-learning-102-copy-attachment-from-one...

or 

2. create a script include in the global application and shift the code that you have written there and make it accessible from all application scopes and call that script include 

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya

Hi @Chaitanya ILCR ,

Copying won't be helpful as it will create the attachment entries two times on the activity stream.
I tried the second approach but that also didn't worked.

Its_Azar
Kilo Sage

Hi there @Swapnil Srivas1 

 

An after insert Business Rule on the target table often runs before ServiceNow finishes re-associating those attachments, so updating sys_attachment.table_name there won’t work reliably. Instead of manually updating sys_attachment, the recommended approach is to let ServiceNow handle the move by mapping the attachment variable (or using producer.attachments.copy(targetTable, targetSysId) in the Record Producer script). If you must script it, run the logic asynchronously (or via a scheduled/queued job) after the record producer finishes, and update both table_name and table_sys_id. Directly changing sys_attachment in a synchronous BR is not supported and often gets overwritten by the platform.

 

☑️ If this helped, please mark it as Helpful or Accept Solution so others can find the answer too.

Kind Regards,

Mohamed Azarudeen Z

Developer @ KPMG

Hi @Its_Azar ,

I tried an async insert business rule and tried to update both table name and table sys id, but that also didn't worked.