I need to Copy an attachment from RITM to a Catalog Task

Allen12
Tera Guru

I need to copy an attachment from the Form or RITM to a Catalog Task.  From what I have found online, this is what I have tried.  However the attachment is not copying over to my Task. I usually work in Workflow Editor but was told this would be a better option.  Any help is Appreciated.

Allen

 

find_real_file.png

 

1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

I wouldn't say Flow Designer is a better option in this case, especially if you're more familiar with and already running a Workflow on the catalog item.  If you must copy attachments, the easiest/best place to do this is in a Business Rule running on the sc_task table after Insert.  All you need is this code in the Advanced Script.

(function executeRule(current, previous /*null when async*/) {

	GlideSysAttachment.copy('sc_req_item', current.request_item, 'sc_task', current.sys_id);

})(current, previous);

The reasons for not copying attachments are that it bloats the database with the same attachment record multiple times, and if the attachment is updated on the RITM or SCTASK, the other is not changed.  A better option is to create a Defined Related List on the SCTASK form to show the attachments for the parent sc_req_item.

https://docs.servicenow.com/bundle/kingston-platform-user-interface/page/administer/form-administration/task/t_CreateDefinedRelatedLists.html

 

 

View solution in original post

10 REPLIES 10

Sure. It's a read-only checkbox that is populated (where appropriate) by this Business Rule:

var gr = new GlideRecord('sys_attachment');
gr.addQuery('u_record', current.request_item.sys_id);
gr.query();
if(gr.hasNext()){
    //set flag on SCTASK
    current.u_ritm_attachment = true; //checkbox
    gs.addInfoMessage('The parent RITM has attachments');
}

Thank you @Ian Mildon 

Hello there, I have a similar request to advise Users that there is an Attachment in the RITM, just checking to see if you got this to work using Ian's suggestion? Regards.

This is the code I used:

find_real_file.png

Appreciate this Allen. Are you able to provide more information? This for a Business Rule based on After / Insert > on the sys_attachment table & your above following script? Regards, Winnie