UI action to copy attachment from incident table to existing work order records

Kunal33
Tera Expert

Hi Team,

We have a requirement to create a UI action--Copy attachment to work order on attachment related list on incident form . With this UI action, when we select attachment and click on this button, it copy the selected attachment and move the attachment to related work orders. 

34 REPLIES 34

plz share the common field between incident table and wm_order table which will be using as reference for copying attachment to that record.

We have field on wm_order tabe named "initiated_from" which store the incident num. 

 

var gr= new GlideRecord('wm_order');
var wn_num = current.number;
gr.addQuery('initiated_from', wn_num);
gr.query();
var sysID="";
if(gr.next()){
sysID = gr.sys_id;
}

GlideSysAttachment.copy('incident', current.sys_id, 'wm_order',sysID);

gs.addInfoMessage("Attachment updated");
var mySysID = current.update();

 

 

Plz use this Script

 

Plz Mark my Solution as Accept and Give me thumbs up, if you find it Helpful.

 

Regards,

Samaksh

I have added addinfomessage and it gave me below result:-

 

var gr= new GlideRecord('wm_order');
var wn_num = current.number;
gs.addInfoMessage("Wokr order"+""+ wn_num);
gr.addQuery('initiated_from', wn_num);
gr.query();
var sysID="";
if(gr.next()){
sysID = gr.sys_id;
gs.addInfoMessage("SysID"+""+ sysID);
}

GlideSysAttachment.copy('incident', current.sys_id, 'wm_order',sysID);

gs.addInfoMessage("Attachment updated");
var mySysID = current.update();

 

Wokr orderundefined// Here itscoming as undefined
Info Message
SysID21702f161bd69d145f42542a2d4bcb2c // this is sys id of any random work order record
Info Message
Attachment updated

Hello @Kunal33 

 

Are you writing this Script on Incident table ??

 

Plz Mark my Solution as Accept and Give me thumbs up, if you find it Helpful.

 

Regards,

Samaksh