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

var gr= new GlideRecord('wm_order');
gr.addQuery('initiated_from', '096a77a09744391088cf78ae2153af35'); // enter any static incident number which is also a number in work order table record just for testing.

gr.query();
var sysID="";
while(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();

 

I tired with this and gave me work order sys id but not copying attachments. 

 

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

 

i think in the above line, we need to use some other thing instead of current.sys_id

Hello @Kunal33 

 

I think 'initiate_from' field is not the reference field so,

 

gr.addQuery('initiated_from', 'INC0197284'); 

 

give Incident number in it, instead of sys_id;

 

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

 

Regards,

Samaksh

Its a reference field  on work order table. thats why i passes sys id.

Ankur Bawiskar
Tera Patron
Tera Patron

@Kunal33 

GlideSysAttachment copy will copy all the files and not the selected ones

Here is what you need to do

1) Create UI action which is client side in related list

2) get the list of checked sysIds from that UI action using g_list.getChecked()

3) then make GlideAjax call and send those sysIds along with incident sysId

4) query work order table with the incident sysId (Assumption is you are storing INC reference in Work order table)

5) once you get the record then use this link to copy the files individually ( since you already know the attachment record sysIds)

How to copy attachment from one File attachment field to another table 

I hope with this information you will be able to achieve your requirement.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Ankur, Can you please elaborate it .