- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-19-2018 10:38 AM
Hello
i would like to copy when the attachment is attached to RITM it should copy over to associated Task as well , i searched in the community , some have i found that business rule , but the issue i am facing here is
When i mark the business rule to run on insert , its not performing any action meaning if i attach an image and if i open the associated task cannot see the image.
and when i change the business rule from insert to update , its acting even strange , when i attach any attachment on RITM and save it and open the task , i cannot see any attachment and if i save the task then i can see the attachement and if i save it again its duplicating the attachement . Am i missing any thing here , can some one help me with this please,
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-21-2018 10:55 AM
Let's try below code on sys_attachment table with after insert BR, I have tested and it works fine.
(function executeRule(current, previous /*null when async*/) {
var sctask = new GlideRecord('sc_task');
sctask.addQuery('request_item', current.table_sys_id);
sctask.addQuery('request_item.cat_item', 'PASS THE SYS_ID OF CATALOG ITEM HERE');
sctask.query();
if(sctask.next()){
var deleteTaskAttachment = new GlideRecord('sys_attachment');
deleteTaskAttachment.addQuery('table_sys_id', sctask.sys_id.toString());
deleteTaskAttachment.addQuery('table_name', 'sc_task');
deleteTaskAttachment.deleteMultiple();
var ritmAttachment = new GlideRecord('sys_attachment');
ritmAttachment.addQuery('table_sys_id', sctask.request_item);
ritmAttachment.query();
if(ritmAttachment.next())
GlideSysAttachment.copy('sc_req_item', ritmAttachment.table_sys_id, 'sc_task', sctask.sys_id);
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-22-2018 01:32 PM
Thank you so much
its working if i attach the attachment from the ritm and its not duplicating
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-18-2020 11:25 AM
Hi, I tried this code. But if the user created a request with attachment, it's not copying the attachment. I have to edit first the RITM before it copy all the attachment. Any thoughts how to fix?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-18-2020 11:26 AM
Hi, I tried this code. But if the user created a request with attachment, it's not copying the attachment. I have to edit first the RITM before it copy all the attachment. Any thoughts how to fix?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-31-2022 05:20 AM
(function executeRule(current, previous /*null when async*/) {
var sctask = new GlideRecord('sc_task');
sctask.addQuery('request_item', current.table_sys_id);
sctask.query();
if(sctask.next()){
var deleteTaskAttachment = new GlideRecord('sys_attachment');
deleteTaskAttachment.addQuery('table_sys_id', sctask.sys_id.toString());
deleteTaskAttachment.addQuery('table_name', 'sc_task');
deleteTaskAttachment.deleteMultiple();
var ritmAttachment = new GlideRecord('sys_attachment');
ritmAttachment.addQuery('table_sys_id', sctask.request_item);
ritmAttachment.query();
if(ritmAttachment.next())
GlideSysAttachment.copy('sc_req_item', ritmAttachment.table_sys_id, 'sc_task', sctask.sys_id);
}
})(current, previous);
i am trying the above script but it is copying to only single task in RITM ( when i attach any attachment on RITM and save it and open the task..).If we have multiple Catalog Task for one RITM it is not working
Can help me on this

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-20-2018 10:23 AM
Have you thought of using Jim Coyne's solution?
https://community.servicenow.com/community?id=community_blog&sys_id=928c2ae1dbd0dbc01dcaf3231f961927&view_source=searchResult
Prevents you from having to duplicate attachments at all. We find it really handy.