Getting base64 encoded data of an attachments of request in a scripted rest api

Ansuha Chipuri
Kilo Guru

Hi,

We have a custom table that extends request table . Lets take table name as ABC

We have a record producer that creates tickets in this ABC table

this record producer has a variable of type Macro - which is an OOB attachment widget.

I have a scripted rest api that pulls all the variables data on the record producer

Now our customer is using second api call which is OOB to get the attachment content. the requirement here is the a scripted api call is returning empty value for attachment variable, here the customer wants to get base64 encodedd data of all the attachments so that he can avoid the second api call.

how i can code my scripted rest api to get all attachments base64 encoded data with the scripted rest api

 

Thanks in advance

 

 

11 REPLIES 11

var attachGr = new GlideSysAttachment();
var
 gr = new GlideRecord('sys_attachment');
 gr.get('0710e3deebb11a10e099f5adbad0cd2f');
 var base64Content = attachGr.getBytes(gr);
            var binaryData = GlideStringUil.base64Encode(base64Content);
  gs.info("binaryData");

Also make sure this script is run in global scope, as you might see conflicts running in custom scopes

Thanks @avieet!

Now getting the new error:

Error: Cannot find function getBytes in object [object GlideSysAttachment].,Detail: Cannot find function getBytes in object [object GlideSysAttachment].
 


Thanks,
Rajashekhar Mushke
Rising star : 2022 - 2024
Community Leader -2018
Connect me on LinkedIn : Rajashekhar Mushke