Want to copy attachment from ritm to a table in servicenow

Priyanka Chaud1
Tera Contributor

Hi I have a requirement where I have to copy attachment from catalog item to a particular table. We have a reference field for that table in the catalog item. @Ankur Bawiskar please help me in this

1 ACCEPTED SOLUTION

@Priyanka Chaud1 

this should work fine

1) after insert BR on sc_req_item

Condition: current.cat_item.name == 'Your Catalog Item Name Here'

Script:

Note: Ensure you give correct variable name of your variable which refers wm_task table

GlideSysAttachment.copy('sc_req_item', current.sys_id, current.variables.variableName.sys_class_name, current.variables.variableName);

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

12 REPLIES 12

ok so i will tell you i have one reference variable which is pointing to wm_task table. Now i want to copy my attachment to same wm_task table as ritm gets created.

I used after insert br on sc_req_item using script but its not working @Ankur Bawiskar 

 var wot = new GlideRecord('wm_task');
        wot.addQuery('sys_id', current.parent);
        gs.info('Parent value comes here' +wot.getRowCount());
        wot.query();
        if (wot.next()) {
        
            var attachment = new GlideSysAttachment();

            var copiedAttachments = attachment.copy('sc_req_item', current.sys_id, 'wm_task', wot.sys_id);
       gs.info('inside attachment ' +copiedAttachments);

@Priyanka Chaud1 

this should work fine

1) after insert BR on sc_req_item

Condition: current.cat_item.name == 'Your Catalog Item Name Here'

Script:

Note: Ensure you give correct variable name of your variable which refers wm_task table

GlideSysAttachment.copy('sc_req_item', current.sys_id, current.variables.variableName.sys_class_name, current.variables.variableName);

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Its working fine thanks @Ankur Bawiskar