Issue with PFX file download

kmrudulanayak
Tera Contributor

 

After downloading a PFX Certificate and attempt to install the Certificate, an error is presented stating - 'This file is invalid for use as the following: Personal Information Exchange''

mceclip0.png

When same Get API call is executed from Postman I am getting proper pfx format file but when tried to execute same call from servicenow, I am unable to open the pfx file which is downloaded (which is an attachment to RITM)and I can also see file size increased when tried to download. Did anyone came across similar issue?

1 REPLY 1

jay241992
Tera Contributor

Hi,

Are you attaching the response directly to the RITM request? If so, it won't work due to the file content type, and you'll need to decode it using base64DecodeAsBytes.

Here’s what you need to do before attaching the file to the RITM:

 

var data = GlideStringUtil.base64DecodeAsBytes(content); // 'content' is the responseBody (file data only)

 

var attachment = new GlideSysAttachment();

// Set up the inputs
var rec = new GlideRecord('incident');
rec.get('78271e1347c12200e0ef563dbb9a7109');
var fileName = 'example.txt'; // up to you......
var contentType = "application/x-pkcs12"
var content = data;

// Write the attachment
var agr = attachment.write(rec, fileName, contentType, content);

gs.info('The attachment sys_id is: ' + agr);