- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-23-2017 03:58 AM
Hi,
I'm writing a function in a script include that exports me some data and adds it as an Attachment to a record.
Example Code is like this
var data = "Name;Firstname;Phone";
data += "\n";
data += "Bauer;Sven;+492408xxx";
data += "\n";
data += "Meier;Karl-Heinz;+492408xxx";
data += "\n";
data += "Müller;Joachim;+492408xxx";
var company = new GlideRecord('core_company');
company.get('ee4fab735f6512006d8ddb765a069c99');
var attachment = new GlideSysAttachment();
var newFile = attachment.write(company, 'Telefonliste.csv', 'text/csv', data);
My Problem now is that the Attachment is encoded in UTF-8 but without BOM.
This makes the Umlaut 'ü' to not be shown correctly in Excel.
Any Ideas how to change the Enocoding to ANSI or add the bom-Marker?
Sven
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-12-2018 10:57 PM
Hi Sven,
I just had the same issue. Unfortunately UTF-8 hates all special characters, even if this encoding should happily display them.
I have tried encoded/decoding into UTF-8 characters, without success.
But I have some good news, and this may be a little hacky but it works for me:
Add "\uFEFF" right at the start of the content.
This is the character encoding for BOM.
So in your case:
var data = "\uFEFFName;Firstname;Phone";
data += "\n";
data += "Bauer;Sven;+492408xxx";
data += "\n";
data += "Meier;Karl-Heinz;+492408xxx";
data += "\n";
data += "Müller;Joachim;+492408xxx";
var company = new GlideRecord('core_company');
company.get('ee4fab735f6512006d8ddb765a069c99');
var attachment = new GlideSysAttachment();
var newFile = attachment.write(company, 'Telefonliste.csv', 'text/csv', data);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-12-2018 01:54 AM
for export: export to excel instead of CSV helps...

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-12-2018 10:57 PM
Hi Sven,
I just had the same issue. Unfortunately UTF-8 hates all special characters, even if this encoding should happily display them.
I have tried encoded/decoding into UTF-8 characters, without success.
But I have some good news, and this may be a little hacky but it works for me:
Add "\uFEFF" right at the start of the content.
This is the character encoding for BOM.
So in your case:
var data = "\uFEFFName;Firstname;Phone";
data += "\n";
data += "Bauer;Sven;+492408xxx";
data += "\n";
data += "Meier;Karl-Heinz;+492408xxx";
data += "\n";
data += "Müller;Joachim;+492408xxx";
var company = new GlideRecord('core_company');
company.get('ee4fab735f6512006d8ddb765a069c99');
var attachment = new GlideSysAttachment();
var newFile = attachment.write(company, 'Telefonliste.csv', 'text/csv', data);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2018 07:43 AM
Hi Oliver,
this works fine.
Thanks a lot
Sven
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-11-2018 01:55 AM
HI Oliver,
The solution can multiple sheets with test/xls?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-13-2018 11:49 PM
Hi Hung,
no, I only write plain Text (with Olivers help now with BOM) into a csv-Attachment.
If you want to write an Excel File, "data" must contain the Base64 Encoded Content of your Excel-File. If you know how to create this, you might post it here.
Sven