UI action to copy attachment from incident table to existing work order records
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-13-2023 12:54 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-13-2023 06:43 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-13-2023 07:39 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-13-2023 10:37 PM
Its a reference field on work order table. thats why i passes sys id.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-13-2023 02:48 AM
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-13-2023 02:53 AM
Hi Ankur, Can you please elaborate it .