Copy attachment from RITM to data source - GlideSysAttachment().copy not working !

Sin
Giga Expert

Hi All,

 I have one requirement to copy the attachment from one table to another table.

Requirement : Whenever a request is placed from catalog item(from only one item),attachment from RITM should be copied to data source table, to a particular data source record. In my case data source record name is TEST and sys_id is 0ec1ab04db8bbf4019d81ffa68961900.

I have created below Business Rule  to achieve this, but its not working .[working only for after update condition not after insert] attachment is not getting attached on TEST data source.

(function executeRule(current, previous /*null when async*/) {
gs.log("Start"); 

var sourceSysID = current.sys_id ;
var targetSysID = '0ec1ab04db8bbf4019d81ffa68961900'; //target record ID
var copyAtt = new GlideSysAttachment();
copyAtt.copy('sc_req_item', sourceSysID, 'sys_data_source', targetSysID);


})(current, previous);

 

BR screenshots has been attached.Can anyone help me to achieve this?

find_real_file.png

find_real_file.png

 

Thanks in Advance!!

13 REPLIES 13

AbhishekGardade
Giga Sage

Hello Sana,

I have tested in my instance and the function GlideSysAttachment.copy('sourcetable', 'sys_id', 'destinationtable', 'sys_id') is working totally fine. Make sure you need to use this in after Insert Business rule in the Attachment (sys_attachment) table. For your reeference, I have used below code snippet:

GlideSysAttachment.copy('incident', '5a1628046ff03200f9ac52b10b3ee4d4', 'incident', '419c50d86f783200f9ac52b10b3ee498');

 But it won't prevent you from inserting duplicate attachments. To prevent this you have to opt slight different approach. You may find that in this thread: Attachment sync REQ-TASK

Checkout this Blog:

https://community.servicenow.com/community?id=community_question&sys_id=93f183e9db98dbc01dcaf3231f96...

Please mark as Correct Answer/Helpful, if applicable.
Thanks!
Abhishek Gardade

Thank you,
Abhishek Gardade

Hi Abhishek,

I have changed BR table to sys_attachment,still its not working 😞 Its working only for after update condition not for after insert condition.

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Sana,

you have created the BR on sc_req_item table after insert

If you are using workflow on sc_req_item then no need for BR; directly use that code in the workflow run script activity

with which user you are testing this?

Mark Correct if this solves your issue and also mark 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 Anukur,

As of now am not using any workflow that is why I have created a BR.Can you please check my BR and help me out.