- 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 10:17 AM
FillClientDocumentFileAttachments();
function FillClientDocumentFileAttachments()
{
var base64dataCSV = 'VGhpcyBpcyBhIFRlc3QgQ1NWIGZpbGUNCg=='; //CSV as BASE64
var decodedBytesCSV = GlideStringUtil.base64DecodeAsBytes(base64dataCSV);
var attachGR = new GlideRecord('sys_attachment');
attachGR.addQuery('table_name', "table_name");
attachGR.addQuery('table_sys_id', "table_sys_id");
attachGR.query();
if(!attachGR.next())
{
var sa = new GlideSysAttachment();
sa.write(clientDocFileGR, clientDocFileGR.u_file_name, 'application/csv', decodedBytesCSV);
}
gs.info("Completed adding attachments.");
}
Vinod Kumar Kachineni
Community Rising Star 2022
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2020 11:46 AM
I credit all of you with workable solutions, and the only reason I marked Mr. Singh as "CORRECT" is because of its' succinctness.
Thanks!