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

added Asifnoor.Its working only for after update condition not for after insert condition.

Yes, thats how it works.

As i said, when you upload an attachment, it is considered to update. Bcoz first attachment will be added in sys_attachment table, but table_sys_id and table_name will be added again as an update.  And you can copy only after you have table_sys_id and table_name. Hence you need to use after update.

Kindly mark the comment as a correct answer and also helpful.

ok.Then How can I copy the attachment for after insert?That is how my requirement is.Is it not possible?

Sin
Giga Expert

Asifnoor I have changed the "When to run condition" to "async",now its working for insert as well.Now the issue is while insert ,attachment is getting attached 2times.

Do you have any idea on this?