- 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-19-2018 11:17 AM
Give a try with before insert.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-20-2018 05:09 AM
When a request is generated before task is generated if i attach the attachement to ritm and after approval once the task is generated its copying the attachment but if i attach another attachment its not
and if i attach after the task is generated by approving the ritm its not attaching the attachment

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-20-2018 06:35 AM
yes, that's because the BR is running onInsert(), if you want to transfer the attachment from RITM to Task after task is created then I think you can have onInsert() BR on sys_attachment table to copy the attachment from RITM to Task table.
(function executeRule(current, previous /*null when async*/) {
var gr = new GlideRecord('sc_task');
gr.addQuery('request_item', current.table_sys_id);
gr.query();
while(gr.next())
GlideSysAttachment.copy('sc_req_item', current.table_sys_id, 'sc_task', gr.sys_id);
})(current, previous);
with below condition.
Let's see if this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-20-2018 06:38 AM
and can we do it for only one catalog item ?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-20-2018 06:57 AM
we can try adding filter in GlideRecord query for catalog item.
(function executeRule(current, previous /*null when async*/) {
var gr = new GlideRecord('sc_task');
gr.addQuery('request_item', current.table_sys_id);
gr.addQuery('request_item.cat_item', 'PASS THE SYS_ID OF CATALOG ITEM HERE');
gr.query();
if(gr.next())
GlideSysAttachment.copy('sc_req_item', current.table_sys_id, 'sc_task', gr.sys_id);
})(current, previous);