The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Copy Attachment from one table to another | Attachment from sysapproval_approver to Parent ticket

DanaWood
Tera Contributor

Hi, 

 

I need help to create Business Rule to copy attachment from the approver record on (sysapproval_approver) to the parent record which is on custom table (x_tech_request) 

I don't want to use flow 

Thanks,

S

 

7 REPLIES 7

Nawal Singh
Tera Expert

Hi @DanaWood ,

 

Please review the below link , there is already solution provided -

 

https://www.servicenow.com/community/developer-forum/copying-an-attachment-from-a-change-to-the-appr...

 

if it's helpful please mark as helpful and accept the solution in order to close the thread.

 

Thank you!!

Ankur Bawiskar
Tera Patron
Tera Patron

@DanaWood 

you can use after insert BR on sys_attachment table

Condition: current.table_name == 'sysapproval_approver'

Script:

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

    // Add your code here
    var gr = new GlideRecord("sysapproval_approver");
    gr.addQuery("sys_id", current.table_sys_id);
    gr.query();
    if (gr.next()) {
        var rec = new GlideRecord('x_tech_request');
        if (rec.get(gr.document_id)) {
            new GlideSysAttachment().copy('sysapproval_approver', gr.getUniqueValue(), 'x_tech_request', rec.getUniqueValue());
        }
    }

})(current, previous);

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

@Ankur Bawiskar  thanks for your reply, it works but every time I add attachment to add all attachment again to the request. 

@Ankur Bawiskar Thanks for your reply! it works but it keeps adding the old attachment with every new one.