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

Hi Sana,

with admin user also you are facing this issue?

Regards

Ankur

 

 

Yes Anukar. Its working only for after update condition not for after insert condition.

Is there anything wrong with my code? am I passing correct source and destination tables?Kindly look into that.

asifnoor
Kilo Patron

Hello Sana,

You need to do this on sys_attachment (after update), bcoz first attachmetn is inserted and then table_sys_id and table_name will be updated. And your Br need to run after update.

Secondly, you need to add a condition, otherwise this will execute eerytime.

So check if current.table_name=="your table name" or current.table_sys_id="your sysid"

Mark the comment as a correct answer and helpful once worked.

Hi Asifnoor,

I have updated as you mentioned, still no changes 😞

find_real_file.png

Okay. Can you add a log statement in your scirpt and tell me if its working or not.