Carry Over Attachment from Task to Task.

prash4
Tera Expert

Hi All.

 

I have a requirement where  attachment needs to carry over from task to task.

usually in task 1 client will upload the attachment, that should carry over to next task and also present in RITM.

 

A quick would really appeciate it.

 

Thank you

2 REPLIES 2

Sandeep Rajput
Tera Patron
Tera Patron

@prash4 Write a onBefore Update business rule on your sc_task table as follows.

 

Screenshot 2023-10-10 at 3.47.45 PM.pngScreenshot 2023-10-10 at 3.52.02 PM.png

 

Here is the script.

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

    // Add your code here
    var glideTask = new GlideRecord('sc_task');
    glideTask.addQuery('parent', current.parent.getValue('sys_id'));
    glideTask.addQuery('short_description', '<short description of your other task>');//Put short description of the taks where you would like to copy the attachments
    glideTask.query();
    while (glideTask.next()) {
        var attachment = new GlideSysAttachment();        
        var copiedAttachments = attachment.copy('sc_task', current.sys_id, 'sc_task', glideTask.getValue('sys_id'));
        gs.info('Copied attachments: ' + copiedAttachments);
    }

})(current, previous);

 

Hope this helps.

Ankur Bawiskar
Tera Patron
Tera Patron

@prash4 

Why to copy same file in multiple records?

This will increase size of sys_attachment table

Why not use this related list custom functionality?

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