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-09-2025 11:32 PM
Code I shared will give the base64 encoded data if you have attachment record sysId
There seems some other error
what debugging have you done so far?
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:35 PM
add gs.info() to debug at correct places because script I shared will work fine to get base64 data
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-13-2025 01:13 AM
Hi Ankur,
I tried your above method as well
Now I am trying to get Base64 content in Background script
Below is the script:
Error and logs:
*** Script: 📂 Fetching Attachment: image.jpg (MIME: image/jpeg)
*** Script: ❌ ERROR: Exception while processing attachment: TypeError: Cannot find default value for object.: no thrown error
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2025 01:15 AM
Also trying on my own
Below Script:
Repeated Error:
*** Script: 📂 Fetching Attachment: image.jpg (MIME: image/jpeg)
*** Script: ✅ Successfully retrieved attachment bytes. Encoding to Base64...
*** Script: ❌ ERROR: Exception while processing attachment: TypeError: Cannot find default value for object.: no thrown error
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2025 01:55 AM
I did help you on getting the base64 data of file.
Further debugging you can perform.
Seems issue with your other script part.
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