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

Ankur Bawiskar
Tera Patron
Tera Patron

@Priyanka Chaud1 

so in catalog item you have a reference variable and you want to copy file to that record i.e. the file which gets attached to RITM during submission?

if yes then you can use workflow run script for this if you are using workflow

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

Hii @Ankur Bawiskar thanks for quick reply yes we have refernce field which is pointing to that table and i want to copy attachment to that table we are using flow designer not workflow for this

@Priyanka Chaud1 

then you can use flow action Copy attachment

check this link has approach

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0813220 

also this link

Unable to copy attachments using flow designer 

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

Hi @Ankur Bawiskar i am using after insert business rule on the target table and this is the query which is not working

var grRITM = new GlideRecord('sc_req_item');
    grRITM.addQuery('sys_id', current.table_sys_id);
    grRITM.addQuery('cat_item''75c843a49732a5109859350f2153af69'); 
    grRITM.query();
        gs.info('tableid' +current.table_sys_id);
    if (grRITM.next()) {
        var wot = new GlideRecord('wm_task');
        wot.addQuery('sys_id', grRITM.parent);
        gs.info(wot.getRowCount() + '----' + grRITM.parent + 'Parent value comes here');
        wot.query();
        if (wot.next()) {
        
            var attachment = new GlideSysAttachment();

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