Sync Attachment between sc_request to sc_task and visa versa

JP6
Tera Contributor

I have a requirement to sync attachment between sc_request and sc_task and vis versa 

I tried the below script using business rule while  it is working for sc_task to sc_request  .  I tried using similar logic to copy from sc_request to sc_task it is not working. Seeking our assistance.

sc_task to sc_request

 

Table:sys_attachment

when to run: after insert

condition: Table name is sc_task 

 

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

    // Add your code here
    var taskRec = new GlideRecord(current.table_name.toString());
taskRec.addQuery("sys_id", current.table_sys_id.toString());
taskRec.query();

if(taskRec.next()){
    GlideSysAttachment.copy(current.table_name.toString(), current.table_sys_id.toString(), "sc_request", taskRec.request.toString());
   
}
 
6 REPLIES 6

@JP6 

it's going in recursion as the other BR might be adding the file again to the other record on attachment copy.

I recommended already to use related list and to avoid copying the same file on multiple records, this will increase attachment table size

TNT: "Related Attachments" Related List 

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

@JP6 

Hope you are doing good.

Did my reply answer your question?

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