How to copy the attachments from catalog tasks to RITM & RITM to catalog task .i.e vice versa

praveen kumar35
Tera Contributor

How to copy the attachments from catalog tasks to RITM & RITM to catalog task .i.e vice versa

2 REPLIES 2

Zach Koch
Giga Sage
Giga Sage

This link shows how to copy a RITM attachment to a Catalog task.  You can do the opposite as well to achieve the reverse.  

Copy attachment

If this resolved your issue, please mark this correct and helpful, thank you!

If this information helped resolve your issue, please remember to mark response correct and thumbs up to help future community members on this information, thanks!

Community Alums
Not applicable

Hi @praveen kumar35 

 

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.

 

Gagan5_0-1669737990075.png

 

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);

 

Gagan5_1-1669738812622.png

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