Base64 conversion for any Attachment
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-07-2025 05:48 AM
Hi Friends,
I have a use case where I need to send an MMS message to a phone number. I learned that any attachment must be converted into Base64 format.
I am using an SMS service 'sndryt' endpoint that requires an API key along with mandatory parameters such as the message, phone number, business unique ID, and organization ID.(I have all with me)
To test the compatibility of the endpoint for handling MMS, I manually converted an image to Base64 using an online converter and passed it as a parameter in Postman. The recipient successfully received the message with the image.
Now, I am trying to achieve the same in ServiceNow via Flow Designer. I have attached an image to an incident record, retrieved its sys_id from the sys_attachment table, and am passing it as input.
I have created a custom action
passing attachment sys_id, phone, b_uid, org_id, message as an input
Below is the next script step I am using:
Script:
I place log info for debugging
Failing at this
"Error processing attachment: TypeError: Cannot find default value for object."
till then able to process everything getting meta data of the attachment
Facing issues with conversion.
Anyone Please Help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-07-2025 06:32 AM
which line is causing the error? did you debug that?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-07-2025 06:37 AM
it is always going to catch case not going to try
Before that I am getting the bytes details as well
only conversion I am not able to achieve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-07-2025 07:00 AM
so basically you want to get base64 encoded data of attachment
If you are running in global scope then this sample script will help you to get baase64 encoded string
Enhance your logic as per this
var gr = new GlideRecord('sys_attachment');
gr.get('d7ff2c044f96cc90fc11fa218110c746');
var StringUtil = new GlideStringUtil();
var gsis = GlideSysAttachmentInputStream(gr.sys_id.toString());
var ba = new Packages.java.io.ByteArrayOutputStream();
gsis.writeTo(ba,0,0);
ba.close();
var base64EncodedData = StringUtil.base64Encode(ba.toByteArray());
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-09-2025 11:17 PM
Thankyou for the solution, But it didn't work,
I am in my global scope, below is my code
Getting the same error as before:
*** Script: Error processing attachment: TypeError: Cannot find default value for object.
Below is the code:
(function execute(inputs, outputs) {