- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-11-2017 12:16 AM
Happy new year!
I want to add a header to a scheduled report (csv). I built an onAfter BR on sys_email table to read the attachment and create a new one:
var tableName = current.getTableName();
var sysId = current.sys_id;
StringUtil = GlideStringUtil;
var sa = new GlideSysAttachment();
var bytesContent = sa.getBytes(tableName, sysId);
var strData = String(Packages.java.lang.String(bytesContent));
...
var newData = header + '\n' + strData;
var att = new Attachment();
var msg = att.write(tableName, sysId, file, type, newData);
This is functioning well except the (German) special characters like ä, ö, ü - it will be displayed as something like this: ï ¿ ½ or a replacement character.
By the way: the original attachment correctly displays all the special characters.
Any help to correctly decode/encode would be appreciated.
Peter
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-11-2017 12:45 AM
Hi Peter,
Following is the code to encode/decode the attachment content
var StringUtil = Packages.com.glide.util.StringUtil;
var attachmentSysId = ''; // sys_id of the attachment record in sys_attachment table
var gr = new GlideRecord('sys_attachment');
gr.addQuery('sys_id', attachmentSysId);
gr.query();
if(gr.next()){
var sa = new Packages.com.glide.ui.SysAttachment();
var binData = sa.getBytes(gr);
var encData = StringUtil.base64Encode(binData);
gs.log("Encoded data for attachment is:"+encData);
var decodedData = StringUtil.base64Encode(encData);
gs.log("Decoded data for attachment is:"+decodedData);
}
Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-23-2023 10:37 PM