The CreatorCon Call for Content is officially open! Get started here.

Copy attachment file from incident to problem

chanikya
Kilo Sage

My script is not working,

GlideSysAttachment.copy('incident', current.parent, 'problem', current.sys_id);

var attach = new GlideSysAttachment();

attach.update(current.request_item.getRefRecord());

or

table : sys_attachment

Condition: current.table_name == 'incident'

var task = new GlideRecord('problem');

task.addQuery('parent',current.sys_id);

task.query();

while(task.next()) {

        GlideSysAttachment.copy('incident', current.parent, 'problem', current.sys_id);

}

1 ACCEPTED SOLUTION

Kishore8
Kilo Guru

Hi Chanikya,



here is the script


Business rule: Copy Incident attachment into Problem


after


table : sys_attachment


insert, update



Script:



var atta = new GlideRecord('problem');


  atta.addQuery('parent', current.table_sys_id);


  atta.query();


  if(atta.next())


{


  var gr = new GlideRecord('sys_attachment');


  gr.addQuery('table_sys_id', atta.sys_id);


  gr.deleteMultiple();


  GlideSysAttachment.copy('incident', current.table_sys_id, 'problem', atta.sys_id);


current.update();



}


View solution in original post

11 REPLIES 11

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hello Chanikya,



Can you please give more info on where you want to transfer the attachment. Is it from Incident to problem table?


yes, Incident table to problem table



find_real_file.png


Hi Pradeep,



Can you please provide any updates on this.


Script should be


GlideSysAttachment.copy('incident', current.sys_id, 'problem', current.problem_id.sys_id);