- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2023 03:47 AM - edited 09-19-2023 05:59 AM
I'm trying to send an attachment in base64, when I print in the logs the base64 string format doesn't appear, I don't understand why, this is my code:
var grAttach = new GlideRecord('sys_attachment');
grAttach .get('01ecf2f84785395002ccefb2e36d438f');
var attachment = new GlideSysAttachment();
gs.info('ATTACHMENT '+attachment.getContentBase64(grAttach));
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2023 04:36 AM
Hi @fabrizio95360 ,
Try the following code and this works in Global scope too.
var StringUtil = new GlideStringUtil();
var gsis = GlideSysAttachmentInputStream("01ecf2f84785395002ccefb2e36d438f");
var baos = new Packages.java.io.ByteArrayOutputStream();
gsis.writeTo(baos);
baos.close();
var base64Data = StringUtil.base64Encode(baos.toByteArray());
gs.info('ATTACHMENT ' + base64Data);
Please mark my answer helpful and accept as solution if it helped you 👍✔️
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2023 04:36 AM
Hi @fabrizio95360 ,
Try the following code and this works in Global scope too.
var StringUtil = new GlideStringUtil();
var gsis = GlideSysAttachmentInputStream("01ecf2f84785395002ccefb2e36d438f");
var baos = new Packages.java.io.ByteArrayOutputStream();
gsis.writeTo(baos);
baos.close();
var base64Data = StringUtil.base64Encode(baos.toByteArray());
gs.info('ATTACHMENT ' + base64Data);
Please mark my answer helpful and accept as solution if it helped you 👍✔️
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2023 06:07 AM
Please mark my answer helpful and accept as solution if it helped you, otherwise please let me know if you need any more help.
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2024 09:22 AM
Hi Anvesh,
The script is helpful, but I am still seeing the scoped error in the logs when executing it and do you know if how we can send this base64 data as key pair value in the json body, would be helpful.
I am sending it after the above code usage this way :
Thank you,
Laxmi.