how to copy attachment from catalog task to RITM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2018 12:55 AM
i was trying to copy the attachement from task to Ritm it was working fine for 1 task and for 2 nd task the system getting hanged

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2018 01:01 AM
HI,
create business rule for copying attachment from one table to another.
table name: sc_req_item
when: after insert
Code:
(function executeRule(current, previous /*null when async*/) {
var att = new GlideSysAttachment();
var src_table = "sc_task"; //source table
var tar_table = "sc_req_item"; //target table
return att.copy(src_table, current.sc_task, tar_table, current.sys_id);
})(current, previous);
Thanks,
Bhojraj Dhakate
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-22-2018 09:14 AM
This is Helpful For me Thank you So much dear Bhojraj Dhakate
Regards,
Dinesh Kumar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2018 06:49 AM
Hi have tried by doing the below code:
After insert
Table: sys_attachment
condition: table_name is sc_task.
it is working fine when we are adding an attachment to first task but it is not working when we try on second task of same RITM
(function executeRule(current, previous /*null when async*/) {
var gr = new GlideRecord('sc_task');
gr.addQuery('sys_id',current.table_sys_id);
gr.query();
var ritm = gr.request_item;
if(gr.next()){
if(gr.request_item.cat_item == 'sys_id of catalog item' ){
GlideSysAttachment.copy('sc_task', gr.sys_id, 'sc_req_item', ritm);
}
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2018 07:20 AM
Hi Prashant,
Please try following code:
table name: sys_attachment
Operation: insert/update
Script:
(function executeRule(current, previous /*null when async*/) {
var id = current.table_sys_id;
var gr = new GlideRecord('sc_task');
gr.addQuery('sys_id', id);
gr.query();
if(gr.next()){
var ritm = gr.request_item;
var att = new GlideRecord('sys_attachment');
att.initialize();
att.file_name = current.file_name;
att.content_type = current.content_type;
att.compressed = current.compressed;
att.table_name = 'sc_req_item';
att.size_bytes = current.size_bytes;
att.size_compressed = current.size_compressed;
att.table_sys_id = ritm;
var attRec = att.insert();
var attDoc = new GlideRecord('sys_attachment_doc');
attDoc.addQuery('sys_attachment', current.sys_id);
attDoc.query();
while(attDoc.next()){
var attDocCopy = new GlideRecord('sys_attachment_doc');
attDocCopy.initialize();
attDocCopy.sys_attachment = attRec;
attDocCopy.position = attDoc.position;
attDocCopy.length = attDoc.length;
attDocCopy.data = attDoc.data;
attDocCopy.insert();
}
}
})(current, previous);
Above code is working for me.
Thanks,
Bhojraj