We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

GlideSysAttachment writeBase64 not working correctly

Victorien
Giga Contributor

Hi !

 

I am having a problem using GlideSysAttachment writeBase64 function.

Currently, I am making a custom PDF using jspdf on the client side and then I am sending the body of the PDF to the server side using Ajax. On the server side, when I use GlideSysAttachment.write() with the required data and the string of the PDF's body, it works but the UTF-8 characters aren't correctly displayed. When I use writeBase64, nothing happens.

 

Is this the right way to do ? 

14 REPLIES 14

Hi,

can you try to update as this to ensure it is not UTF-8 encoding

var AttachAjaxUtil = Class.create();
AttachAjaxUtil.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    attach: function() {
        try {
            // Parameters
            var sysId = this.getParameter('sys_id');
            var tableName = this.getParameter('table_name');
            var filename = this.getParameter('filename');
            var type = this.getParameter('type');
            var attachment = "\uFEFF" + this.getParameter('attachment');

            var rec = new GlideRecord(tableName);
            rec.get(sysId);
            var aId = new GlideSysAttachment().write(rec, filename, type, attachment);

            return JSON.stringify({attachmentID: aId});
        } catch (e) {
            gs.log("AAU - Error : " + e.toString());
        }
        return null;
    },
    type: 'AttachAjaxUtil'
});

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

It didn't work, sadly 😞 

Hi,

then I doubt it can be achieved

Because in past I have tried this for text file and it worked with that workaround

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

Yeah I think it doesn't work with PDF, sadly.

Thanks for your help anyway and if anyone finds a solution, please share!

Thanks for the update.

You can use this PDF customized solutions from links below

Generating a PDF from HTML

I am a creator — PDF Document Generator - Walter Brame

Use this share utility:

https://developer.servicenow.com/app.do#!/share/contents/3429377_pdf_generator?v=1.02&t=PRODUCT_DETA...

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader