Convert Attachment as Binary files.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2020 02:31 AM
Hi,
Is it possible to convert service now attachment as binary files using script. If yes, can you share any test script? I've analysed Service now provide capability to convert base64 and bytes.
Regards,
Suresh
Suresh.
- Labels:
-
Incident Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2020 02:38 AM
Hey sureshloganathan,
Try this Code:
var StringUtil = new GlideStringUtil();
var attachments = new GlideSysAttachment();
var gR = new GlideRecord('sys_attachment');
gR.addEncodedQuery('table_name=incident^table_sys_id='+current.sys_id);
gR.query();
while(gR.next())
{
var binData = attachments.getBytes(gR);
var encData = StringUtil.base64Encode(binData);
gs.print(binData);
gs.print(encData);
gs.print('**************');
}
If my answer helps you Mark my Answer Correct and Helpful.
Thanks,
Namrata.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2020 02:41 AM
Namrata,
I'm looking for binary file conversion.
var binData = attachments.getBytes(gR); -- helps to binary conversion. i.e., binary and bytes are same?
Regards,
Suresh
Suresh.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2020 02:42 AM
Hey sureshloganathan,
Below code is converting just the one attachement try this one also:
var sa = new GlideSysAttachment();
var binData = sa.getBytes('incident', 'd71da88ac0a801670061eabfe4b28f77');
var encData = GlideStringUtil.base64Encode(binData);
gs.print(binData);
gs.print(encData);
If my answer helps you Mark my Answer Correct and Helpful.
Thanks,
Namrata Khabale.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2020 02:46 AM
Namrata,
Thanks for your response. Question - Bytes and binary both are same?
Regards,
Suresh
Suresh.