copy attachments from request to RITM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-24-2016 11:46 PM
Hi,
I have a requirement to copy all the attachments from Request to the corresponding RITMs.
I have written an After-Insert Business rule on the Request table to achieve the same. But it seems the code is not working as expected.
Name: Copy Attachments to RITM
Table: Request (sc_request)
When to run: After - Insert
Script:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('request', current.sys_id);
ritm.query();
while(ritm.next())
{
GlideSysAttachment.copy('sc_request', current.sys_id, 'sc_req_item', ritm.sys_id);
}
})(current, previous);
Any lead will be appreciated. Thanks in advance!!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-24-2016 11:55 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-25-2016 12:01 AM
I wouldn't copy the attachments as these would just add duplicate records. Instead try a custom related list.
"Related Attachments" Related List
Improving the Attachments List View
Showing Requested Item Attachments on the Catalog Task Form
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-25-2016 12:14 AM
Hi Kalai,
Thanks for your reply. But actually I want to copy attachments so that users will be able to see the same attachments on the Service portal view. The community thread will be fine for the natiave view but for my requirement, I need to copy attachments from request to RITM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-25-2016 12:27 AM
Writing an After-Insert Business rule on the Request table will not work here. Because when you are attaching an attachment in a REQ, it is not inserting anything on Request table.
Write the below code in a After-Insert BR on sys_attachment table:
(function executeRule(current, previous /*null when async*/) {
var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('request', current.table_sys_id);
ritm.query();
while(ritm.next())
{
GlideSysAttachment.copy('sc_request', current.table_sys_id, 'sc_req_item', ritm.sys_id);
}
})(current, previous);
But, it will create duplicate records. Below link can help to remeove duplicates. Or you have one other way also. You have to delete all the attachment first then have to copy.
Copy Attachment with out duplicates