How to copy the attachments from catalog tasks to RITM & RITM to catalog task .i.e vice versa
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2022 09:42 AM
How to copy the attachments from catalog tasks to RITM & RITM to catalog task .i.e vice versa
- Labels:
-
Personal Developer Instance

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2022 10:24 AM
This link shows how to copy a RITM attachment to a Catalog task. You can do the opposite as well to achieve the reverse.
If this resolved your issue, please mark this correct and helpful, thank you!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-29-2022 08:22 AM - edited ‎11-29-2022 08:40 AM
I am not sure, if you have got what you were looking for. However, below is the code snippet I used to achieve the requirement to show attachments attached in catalog task to RITM. As an additional, requirement I have considered Work order and Work order task. Obviously, you can do the vice versa as well by modifying the code.
1. First, I created a relationship under system definition. Here I have named the relationship as RITM attachments and selected Applies to table - sc_req_item and Queries from table - sys_attachment. This will act as the related list where you see all the attachments from Catalog task, work order/work order task.
***Note - Here Applies to table is the Parent and the Query from table act as current. In case, if you select Applies to table as Global, then the Related list will be visible Globally.
Then, write the below code
(function refineQuery(current, parent) {
//Current record Attachments
var qc = current.addQuery('table_sys_id', parent.sys_id);
//Request Attachments
qc.addOrCondition('table_sys_id', parent.request.sys_id);
//Catalog Task Attachments
var tsk = new GlideRecord('sc_task');
tsk.addQuery('request_item', parent.sys_id);
tsk.query();
var tskIDArr = [];
while (tsk.next()) {
tskIDArr.push(tsk.sys_id.toString());
}
var tskIDStr = tskIDArr.join();
qc.addOrCondition('table_sys_id', 'IN', tskIDStr);
//Work Order Attachments
var woe = new GlideRecord('wm_order');
woe.addQuery('initiated_from', parent.sys_id);
woe.query();
var wskIDArr = [];
while (woe.next()) {
wskIDArr.push(woe.sys_id.toString());
}
var wskIDStr = wskIDArr.join();
qc.addOrCondition('table_sys_id', 'IN', wskIDStr);
//Work Order task Attachments
var woet = new GlideRecord('wm_task');
woet.addEncodedQuery('parent.ref_sm_order.initiated_from='+parent.sys_id);
woet.query();
var wstkIDArr = [];
while (woet.next()) {
wstkIDArr.push(woet.sys_id.toString());
}
var wstkIDStr = wstkIDArr.join();
qc.addOrCondition('table_sys_id', 'IN', wstkIDStr);
//Do not include attachments not associated with a record
current.addNotNullQuery('table_sys_id');
})(current, parent);
And this how the new related list created will have all the attachments. This will provide just the link to the attachments and will not be copying the attachments itself.
Please mark as helpful/click like button, if the solution was in line with your expectations.
Regards,
Gagan k