- 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 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:27 AM
That's perfect. This is exactly what I need. Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-17-2023 04:07 PM
Regarding the following line:
if(gr.get("ATTACHMENT_SYSID")) {
is ATTACHMENT_SYSID the sys_id of the sys_attachment table OR the sys_id of the attachment/file?
-- If it is the sys_id of the attachment/file, what if that object is random or unknown?
-- It would make more sense if it was the sys_id of the table, since the file could be different for each task created.
-- I am possibly WAY overthinking this too. LOL
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-02-2020 07:58 AM
Hi,
Looks like you are trying to copy an attachment?
If not then how did the document get to attachment table? What record is it currently linked to?
-Anurag