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

Hello @Kunal33 

 

You need to set atleast one field in wm_order table, you can't create a empty record.

 

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

 

Regards,

Samaksh

Lets say we have an incident whose num is inc 123 and we have created work order by this incident. we have support two work order created wo123 and wo234. if we attach an attchement test.docs on inc123. on this inc we have a ui action on attachment related list. 

if we click on ui action on inc123, it will copy the existing attachment test.docs on wo123 and wo234.

I hope my req is clear now

 

Plz Use this script with correct field names

 

 

var gr= new GlideRecord('wm_order');
var wn_num = current.number;
gr.addQuery('work_order_number_field_name', 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 Mark my Solution as Accept and Give me thumbs up, if you find it Helpful.

 

Regards,

Samaksh

work_order_number_field_name

which field you are referring here?

wo123 the field which has this value in wm_order table.