Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Copy attachment file from incident to problem

chanikya
Mega 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

Hi Pradeep,



I have written script as you suggested on after business rule.


find_real_file.png







But attachment was not effected in Problem table, Could you please suggest me .




find_real_file.png


Sumedh Kharode1
Kilo Expert

configure Incident UI Action 'Create Problem' and add script as

prob.parent=current.sys_id;

Now create a after business rule on problem table while insert/update as below:

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