How to get Base64 content of all attachments on Incident?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-20-2017 12:55 PM
I have been reading about 'GlideSysAttachment.getBytes()', but it started to confuse me. As far as I understand it should be called like this:
var sa = new GlideSysAttachment();
var bytes = sa.getBytes(attachment.getValue("table_name"), attachment.getValue("table_sys_id"));
var content64 = GlideStringUtil.base64Encode(bytes);
What confuses me is that you have to use 'table_sys_id'. That you have to use the sys id of the incident instead of the attachment. So how do you differentiate between different attachments? What if you need to get all attachments on an Incident, how would you get the second attachment? I tried to replace 'table_sys_id' with 'sys_id', but that returned empty bytes...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-22-2017 02:40 AM
I am trying the Attachment API approach, but not sure what I'm doing wrong. I could successfully get the data and it seemed like correct byte data when I print the data. Though after encode in base64 and decoding by only decoders, it does not give the correct file. Do you know what is wrong in the below code?
var request = new sn_ws.RESTMessageV2();
request.setEndpoint('https://<instance>.service-now.com/api/now/attachment/<sys_id>/file')');
request.setHttpMethod('GET');
//Eg. UserName="admin", Password="admin" for this code sample.
var user = 'admin';
var password = 'admin';
request.setBasicAuth(user,password);
request.setRequestHeader("Accept","*/*");
var response = request.execute();
var body = response.getBody();
var content64 = GlideStringUtil.base64Encode(body.toString());
gs.print(content64);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-22-2017 09:01 AM
I am not following the script. What end point are you using?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-22-2017 09:10 AM
I'm using the instance this is running on. So it points back to itself. How else would I be able to retrieve the attachments?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-22-2017 09:20 AM
Can you please paste in the endpoint? Don't need your instance name just the URL after that. Otherwise I don't know which API you are using and cannot help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-22-2017 09:35 AM
Sorry about that Michael. It's https://<instance>.service-now.com/api/now/attachment/<sys_id>/file
Today, I have tried out a different approach, which encountered max size string errors. So I am assuming this approach will encounter the same problem. The problem was that String variables have a max size of 16MB 😕