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

Jaspal Singh
Mega Patron
Mega Patron

Hi Chanikya,



You can have this written on Problem table with below snippet.



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



considering you want to copy all attachments from incident to problem record.


Hi Jaspal,



i have tried this script earlier, not working



after


find_real_file.png


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();



}


Thanks Kishore!



It is working fine.


@Chankiya, Is this line GlideSysAttachment.copy('incident', current.sys_id, 'problem', current.problem_id.sys_id); not working for you?