- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-02-2020 07:51 AM
The attachment is already in the sys_attachment table. In a script, how would I add an attachment to a specific Incident record?
I know I would have to query for a specific attachment in the sys_attachment table, but I don't know how to assign that specific sys_id of an attachment to be able to have it attached to an Incident if I use a script.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-02-2020 07:58 AM
Hello Mike,
You need to update table_sys_id in the sys_attachment table of your attachment with the sys_id of your incident. Then the attachment will be linked to your incident automatically. Here is the sample script.
update the sys_ids with your actual sysids and check.
var gr = new GlideRecord("sys_attachment");
if(gr.get("ATTACHMENT_SYSID")) {
gr.table_sys_id="INCIDENT_SYSID";
gr.table_name="incident";
gr.update();
}
Mark the comment as a correct answer and helpful if it has answered your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-02-2020 08:08 AM
The record producer has 'current.setAbortAction(true);' so it doesn't get to retain the attachment that a user picks, in which case a script is used to set the fields in a record, and I would also like to attach an attachment that a user picks while attempting to submit a record. Because the attachment gets placed into the sys_attachment table anyways, I figured I would grab it from there.
I tried GlideSysAttachment.copy(sourcetable,sys_id,destinationtable,sys_id) but it didnt work for me. I will keep trying.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-02-2020 08:23 AM
If the attachment is on record producer, it should get copied to the target record by itself, why is that not happening.
-Anurag
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-02-2020 08:16 AM
Hi Mike,
Can you explain your business use-case/requirement around this?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader