Attachment to Base64 Conversion in Scoped App
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
I want to transfer attachment from ServiceNow to third part in Base64 format in scoped application. Below is my script and the error is "Scope does not have read access to table sys_attachment". I am trying this in custom action(flow designer)
(function execute(inputs, outputs) {
outputs.invoicecase_number = '';
outputs.file_name = '';
outputs.file_type = '';
outputs.base64_output = '';
// Get the AP Case record
var caseGR = new GlideRecord('sn_ap_cm_ap_case');
if (caseGR.get(inputs.invoice_number_sysid)) {
outputs.invoicecase_number = caseGR.getValue('number');
// Use GlideSysAttachment ONLY (no sys_attachment table query)
var gsa = new GlideSysAttachment();
var att = gsa.getAttachment('sn_ap_cm_ap_case', inputs.invoice_number_sysid);
// Fetch the first attachment
if (att.next()) {
outputs.file_name = att.getFileName();
outputs.file_type = att.getContentType();
// Get bytes from attachment using sys_id
var bytes = gsa.getBytes(att.getSysID());
outputs.base64_output = GlideStringUtil.base64Encode(bytes);
}
}
})(inputs, outputs);
@Ankur Bawiskar Please help with this
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
54m ago
2 approaches
1) create custom flow action in global scope and call it from your flow in scoped app
OR
2) ensure you add Cross Scope Privilege record so that sys_attachment table can be allowed to READ from your scope. you need to create this record in your custom scope
Also for scoped app this is small code to get base64
Your script won't work in scoped app as getBytes() is not supported
var gr = new GlideRecord('sys_attachment');
gr.get('3fd6017407d3dc50540bf2508c1ed027');
var sysAtt = new GlideSysAttachment();
var base64Data = sysAtt.getContentBase64(gr);
gs.info(base64Data);
💡 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
