GlideSysAttachment not working for xlsx

SD35
Tera Expert

When I run this code, and when the generated excel file that is downloaded and opened gives the following error:

The code works for content type xls and csv's.

var attachment = new GlideSysAttachment();

var rec = new GlideRecord('incident');
rec.get('540c24151b5f0550a6500f2bdc4bcbaa');
var fileName = 'example.xlsx';
var contentType = 'application/xlsx';
var content = 'The text that is stored inside my file';

var agr = attachment.write(rec, fileName, contentType, content);
 
find_real_file.png
4 REPLIES 4

Kieran Anson
Kilo Patron

Hi,

for the content variable, is the text you've used just placeholder or what you're actually trying to push? If so, that would be the issue as an xlsx file expects a certain type of encoding. CSV on the other hand is just a comma separate text file

Yes its a simple placeholder. 

But ultimately i will try to do a key value pair something like this:

But this is the second step

find_real_file.png

But Trying to use the documentation and just change the content type example: https://developer.servicenow.com/dev.do#!/reference/api/rome/server/no-namespace/c_GlideSysAttachmentScopedAPI which is the first step

Ed13
Tera Contributor

Try replace the content type piece  with the following: 

 

var rec = new GlideRecord('incident');
rec.get('540c24151b5f0550a6500f2bdc4bcbaa');
var fileName = 'example.xlsx';
var contentType = '*/*';
var content = 'The text that is stored inside my file';

No this does not work.