- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2020 09:10 AM
Hi,
I see that you can add a new attachment record using the GlideSysAttachment.write()...
But is it possible to insert directly into that table from a script include?
The sys_attachment table does not seem to have a "content" column.
e.g. ==>
var sRec = new GlideRecord('sys_attachment');
sRec.initialize();
sRec.setValue('filename', 'my.csv');
sRec.setValue('sizebytes', {the size of the csv file});
sRec.setValue( {where ever the content is}, {the csv data});
sRec.insert();
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2020 09:30 AM
Hi,
Try using something as below. If required execute it in background script & then check sys_attachment table.
ar attachtable=new GlideRecord('sys_attachment');
attachtable.initialize();
var attachfile = new GlideSysAttachment();
attachfile.write(attachtable, 'abcd.xls','test/csv', 'abcdsample');
Thanks,
Jaspal Singh

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2020 09:30 AM
Hi,
Try using something as below. If required execute it in background script & then check sys_attachment table.
ar attachtable=new GlideRecord('sys_attachment');
attachtable.initialize();
var attachfile = new GlideSysAttachment();
attachfile.write(attachtable, 'abcd.xls','test/csv', 'abcdsample');
Thanks,
Jaspal Singh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2021 10:44 PM
how to add pdf in sys_attachment table if i have URL of pdf
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2022 12:01 AM
can you insert an image by using this script

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2020 09:51 AM
Hi tobrien
You can upload attachment in sys_attachment table with the help of GlideSysAttachment.copy
Example:
var sourceSysID = '1db6b56e6fa58f4882d1cf164b3ee4bf';
var targetSysID = current.sys_id;
var copyAtt = new GlideSysAttachment();
copyAtt.copy('kb_knowledge', sourceSysID, 'sc_req_item', targetSysID);
Here is the script I used in workflow to attach files in Service Catalog Request Items. Modify this script for your tables and see if it works. This is not the ideal way but a workaround I found to do it after trying so many other ways.
More info here Copy Attachments from Record to Record - ServiceNow Wiki
If it help mark helpful or correct
Thanks and regards
Anil