Copy attachment from RITM to data source - GlideSysAttachment().copy not working !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-01-2019 12:28 AM
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?
Thanks in Advance!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-01-2019 12:44 AM
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:
Please mark as Correct Answer/Helpful, if applicable.
Thanks!
Abhishek Gardade
Abhishek Gardade
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-01-2019 01:40 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-01-2019 12:52 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-01-2019 01:42 AM
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.