Reading a PDF attachment - Unable to decompress the gzip file received from sys_attachment_doc table

AnkitS1128
Tera Contributor

Here's a piece of code written in ServiceNow Server side UI Action. The purpose of this code is used to retrieve the content of a attached PDF file which is stored in a encrypted format in the sys_attachment_doc table. Now, in the end of the code, there will be a variable called "encodedString" which is retrieving the file in gzip format. I need to retrieve the entire content of that PDF in a readable string form -

 

var recordId = current.getUniqueValue();
var getAttachementDetails = new GlideRecord("sys_attachment");
getAttachementDetails.addQuery('table_sys_id', recordId);
getAttachementDetails.query();
while (getAttachementDetails.next()) {
       var attachmentName = getAttachementDetails.file_name.toString();
       var encodedString = "";
       var getAttachedEncodedStrings = new GlideRecord('sys_attachment_doc');
       getAttachedEncodedStrings.addQuery('sys_attachment', getAttachementDetails.getUniqueValue());
       getAttachedEncodedStrings.orderBy('position');
       getAttachedEncodedStrings.query();
       while (getAttachedEncodedStrings.next()) {
                 encodedString += GlideStringUtil.base64Decode(getAttachedEncodedStrings.getValue('data'));
       }
       gs.addInfoMessage(encodedString);
}

 

 

Please see the attachment for the output I am receiving in encodedString variable.

AnkitS1128_0-1739969811009.png

 

0 REPLIES 0