Script to copy attachments from catalog item to RITM, or from notification to RITM

MB12
Kilo Sage

I have a workflow event triggering a notification in which I'm trying to attach some files to. Can anyone help with either a workflow script or business rule to copy attachments from the catalog item to the RITM so that they can be included in the notification. 

 

I've tried attaching the files to the notification (and checked include attachments). Then used the below workflow script to copy them from notification to the RITM. However, the RITM attachments come through empty:

var copyAttachFile = new GlideRecord('sys_attachment');
copyAttachFile.addQuery('table_name','sysevent_email_action');
copyAttachFile.addQuery('table_sys_id','notification sys_id'); 
copyAttachFile.query();

while (copyAttachFile.next()) {
copyAttachFile.table_name = 'sc_req_item';
copyAttachFile.table_sys_id = current.sys_id;
copyAttachFile.insert();
}

I also have the attachments on the catalog item. It'd be great if it were possible to copy catalog item attachments to the RITM for use in the event triggered notification.

 

Thank you!

1 ACCEPTED SOLUTION

Mike Patel
Tera Sage

you can add below script to run script to copy attachment from catalog item to RITM

GlideSysAttachment.copy('sc_cat_item', current.cat_item, 'sc_req_item', current.sys_id);

View solution in original post

4 REPLIES 4

Sajilal
Mega Sage

Use GlideSysAttachment.copy('TABLE 1', current.sys_id, 'Table 2', Table 2 sys_id);

Refer https://community.servicenow.com/community?id=community_question&sys_id=eb8fdfb6db3b2b44190dfb24399619a2

Please Mark as Correct if this solves your issue and also mark ???? Helpful if it helps resolve your problem.

Thanks,
Saji

Mike Patel
Tera Sage

you can add below script to run script to copy attachment from catalog item to RITM

GlideSysAttachment.copy('sc_cat_item', current.cat_item, 'sc_req_item', current.sys_id);

hi @Mike Patel ,

I tried with above code but, it only copies in the activities section, we also need it in the header.
any idea how to achieve it other that business rule.

Regards,
Kalpana

Thank you, Mike! This was by far easier than any other solution I came across (trying to query the sys_attachment and sys_attachment_doc tables).