- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-29-2022 08:57 AM
Hi, i have a requirement where user needs to attach one document(pdf) on multiple tasks like around 100 incidents.
could anyone please help me!
thanks,
sry
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-29-2022 01:44 PM
Hello sry,
So, me recommendation is simple:
- From those 100 incidents, manually attach the file to one of them
- Go to the sys_attachment table, locate the file that you added, by filtering records where:
- table name = incident
- table sys id = your incident sys_id
- Create a fix script with the following code:
var orig_incident_id = "<sys_id of the incident where you added the attachment>"; copyAtt(orig_incident_id); function copyAtt(orig_incident_id){ var gr = new GlideRecord("incident"); gr.addEncodedQuery("<add your query to pick the other 99 incidents"); gr.query(); var counter = 0; while(gr.next()){ new GlideSysAttachment().copy("incident", orig_incident_id, "incident", gr.sys_id); ++counter; } gs.info("copied attachment to " + counter.toString() + " records"); }​
This should do the trick!!
Please, if this answer is relevant for you, please mark it as correct and helpful.
Thanks,
Filipe

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-29-2022 01:44 PM
Hello sry,
So, me recommendation is simple:
- From those 100 incidents, manually attach the file to one of them
- Go to the sys_attachment table, locate the file that you added, by filtering records where:
- table name = incident
- table sys id = your incident sys_id
- Create a fix script with the following code:
var orig_incident_id = "<sys_id of the incident where you added the attachment>"; copyAtt(orig_incident_id); function copyAtt(orig_incident_id){ var gr = new GlideRecord("incident"); gr.addEncodedQuery("<add your query to pick the other 99 incidents"); gr.query(); var counter = 0; while(gr.next()){ new GlideSysAttachment().copy("incident", orig_incident_id, "incident", gr.sys_id); ++counter; } gs.info("copied attachment to " + counter.toString() + " records"); }​
This should do the trick!!
Please, if this answer is relevant for you, please mark it as correct and helpful.
Thanks,
Filipe
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-29-2022 02:25 PM
thank you so much Felipe, this worked.