Hi Ankur,

We are receiving the responseBody in Binary format. We want the responseBody to be attached as a pdf file to a current record. So using below code.

var base64string = GlideStringUtil.base64Encode(responseBody);

var attCreator = new GlideRecord('ecc_queue');
     attCreator.agent = "AttachmentCreator";
     attCreator.topic = "AttachmentCreator";
     attCreator.name =   "test1.pdf" + ":" + 'pdf';
     attCreator.source = tablename+":"+recordsys_id;

attCreator.payload = base64string;
     attCreator.insert();

 

But it is attaching an empty file. when I try below code:

var value = GlideStringUtil.base64Decode(responseBody);

var attCreator = new GlideRecord('ecc_queue');
     attCreator.agent = "AttachmentCreator";
     attCreator.topic = "AttachmentCreator";
     attCreator.name =   "test1.pdf" + ":" + 'pdf';
     attCreator.source = tablename+":"+recordsys_id;

attCreator.payload = base64string;
     attCreator.insert();

 

This is returning corrupted file and unable to open it. Could you please suggest an alternative way to convert binary format response into an attachment pdf.

 

Thanks.