- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-10-2019 05:15 PM
Hi Guys,
I am unable to make the below code work. I am trying to send an attachment via REST message by encoding it to Base64 first. The records are getting created in the third party system without the base64 bit. Any ideas?
(function executeRule(current, previous /*null when async*/) {
try {
var attachObj = {};
var grAttachIncident = new GlideRecord ('sys_attachment');
grAttachIncident.addQuery ('table_sys_id', current.getUniqueValue());
grAttachIncident.query();
if (grAttachIncident.next()){
attachObj.u_file_name = grAttachIncident.file_name + '';
attachObj.u_table_name = grAttachIncident.table_name + '';
attachObj.u_content_type = grAttachIncident.content_type + '';
attachObj.u_table_sys_id = current.getUniqueValue() + '';
attachObj.u_task_number = current.number + '';
//encode attachment
attachObj.u_base64 = new GlideSysAttachment().getContentBase64(grAttachIncident);
var body = JSON.stringify(attachObj);
gs.info(body);
var rAttach = new sn_ws.RESTMessageV2('Network Incidents', 'Post_Inc_Attac');
rAttach.setRequestBody(body);
var responseAttach = rAttach.execute();
var httpStatusAttach = responseAttach.getStatusCode();
gs.print("http response status_code: " + httpStatusAttach);
}
}
catch(ex) {
var message = ex.getMessage();
}
})(current, previous);
P.S. I am using an instance which is on London.
Thanks,
Mussie
Solved! Go to Solution.
- Labels:
-
flow designer
-
Orchestration
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-11-2019 02:07 PM
Thanks Sachin.
I later realized that 'getContentBase64' doesn't worked in Global, I changed my code as below and it worked:
var sa = new GlideSysAttachment();
var binData = sa.getBytes(grAttachIncident);
attachObj.u_base64 = GlideStringUtil.base64Encode(binData);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-10-2019 06:04 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-11-2019 02:07 PM
Thanks Sachin.
I later realized that 'getContentBase64' doesn't worked in Global, I changed my code as below and it worked:
var sa = new GlideSysAttachment();
var binData = sa.getBytes(grAttachIncident);
attachObj.u_base64 = GlideStringUtil.base64Encode(binData);