- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-29-2025 02:10 AM
Hi All,
We have an integration requirement where we will be sending attachments from Incidents to third party application. I am currently doing it using flow designer action.
The main isue that I am facing is the mix of base64 content when multiple attachments are attached to an Incident.
If I am adding a single attachment, it's working absolutely fine. The third party is also able to retrieve and read the attachment. But, the problem is when there are multiple files added , the base64 content gets mixed between the files. Hence, the other integrated environment are not able to read these corrupted files though they are able to retrieve it.
Here's my code -
(function execute(inputs, outputs) {
// ... code ...
var inc = new GlideRecord('incident');
inc.addQuery('sys_id',inputs.incident_sysid);
inc.query();
if(inc.next())
{
outputs.incnumber = inc.number;
outputs.postnumber = inc.correlation_id;
}
var sa = new GlideSysAttachment();
var gr = new GlideRecord('sys_attachment');
gr.addQuery('sys_id', inputs.attachment_sysid);
gr.addQuery('table_name', 'incident');
gr.setLimit(1);
gr.query();
var attachments = [];
if (gr.next()) {
var bytesInFile = sa.getBytes('incident', inputs.incident_sysid);
var base64string = GlideStringUtil.base64Encode(bytesInFile);
// var base64Content = sa.getBase64Content(gr);
gs.log('base64' +base64string);
attachments.push({
filename : gr.getValue('file_name'),
content_type: gr.getValue('content_type'),
content: base64string
});
}
outputs.base64 = JSON.stringify(attachments);
})(inputs, outputs);The file name, content_type are working fine but the content of base64 is giving me the issues.
Any help will be appreciated.
Thanks in Advance !
Nayan
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
Thanks all for your help ! @Ankur Bawiskar , @Dinesh Chilaka
I was finally able to resolve this issue. I learnt that "getBase64Content" is only supported in Scoped application for the flow designer. I have modified my script accordingly, here's my final script .
(function execute(inputs, outputs) {
// ... code ...
var inc = new GlideRecord('incident');
inc.addQuery('sys_id',inputs.incident_sysid);
inc.query();
if(inc.next())
{
outputs.incnumber = inc.number;
outputs.zendesknumber = inc.correlation_id;
}
var sa = new GlideSysAttachment();
var gr = new GlideRecord('sys_attachment');
gr.addQuery('sys_id', inputs.attachment_sysid);
gr.addQuery('table_name', 'incident');
gr.setLimit(1);
gr.query();
var attachments = [];
if (gr.next()) {
var gsa = (typeof GlideSysAttachment != 'undefined') ? (new GlideSysAttachment()) : (new Packages.com.glide.ui.SysAttachment());
var attachmentData = gsa.getBytes(gr);
var encData = GlideStringUtil.base64Encode(attachmentData);
attachments.push({
filename: gr.getValue('file_name'),
content_type: gr.getValue('content_type'),
content: encData
});
}
outputs.base64 = JSON.stringify(attachments);
})(inputs, outputs);
This helped my issue while sending attachments in corrupted file. Every attachment is sent properly with the corresponding File Name, File Extension and the Base64 content.
Thanks,
Nayan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2026 11:42 PM
Hi @nayanmule ,
If you have integration hub plugin installed the you can try with "multipart/form-data" in your flow action. For more info check this ServiceNow support article.
If you use this approach then you don't need to script anything.
If my answer helps then please mark it helpful & accept this solution.
Thanks,
Utpal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
Thanks all for your help ! @Ankur Bawiskar , @Dinesh Chilaka
I was finally able to resolve this issue. I learnt that "getBase64Content" is only supported in Scoped application for the flow designer. I have modified my script accordingly, here's my final script .
(function execute(inputs, outputs) {
// ... code ...
var inc = new GlideRecord('incident');
inc.addQuery('sys_id',inputs.incident_sysid);
inc.query();
if(inc.next())
{
outputs.incnumber = inc.number;
outputs.zendesknumber = inc.correlation_id;
}
var sa = new GlideSysAttachment();
var gr = new GlideRecord('sys_attachment');
gr.addQuery('sys_id', inputs.attachment_sysid);
gr.addQuery('table_name', 'incident');
gr.setLimit(1);
gr.query();
var attachments = [];
if (gr.next()) {
var gsa = (typeof GlideSysAttachment != 'undefined') ? (new GlideSysAttachment()) : (new Packages.com.glide.ui.SysAttachment());
var attachmentData = gsa.getBytes(gr);
var encData = GlideStringUtil.base64Encode(attachmentData);
attachments.push({
filename: gr.getValue('file_name'),
content_type: gr.getValue('content_type'),
content: encData
});
}
outputs.base64 = JSON.stringify(attachments);
})(inputs, outputs);
This helped my issue while sending attachments in corrupted file. Every attachment is sent properly with the corresponding File Name, File Extension and the Base64 content.
Thanks,
Nayan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
I believe I also shared a working solution.
Just that you didn't mention you are in scoped app, I shared logic for global scope.
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader

