Attachment is not opening

Krutika Kulkar1
Tera Contributor

Hi Team,

 

I am trying to attach some API response as an excel file to some record in ServiceNow. The file is getting attached to the record, but when I am trying to open it, it is showing one error message as below:-

 

KrutikaKulkar1_0-1724064471407.png

 

Please check the below mentioned code I have written and help me to resolve this issue.

 

var fileResponse = this.utils.makeApiCall("GET", "/reporting/exports/" + exports_id + "/download", "", this.getAuthenticationObject());                      
 
 if (fileResponse && (fileResponse.getStatusCode() == "200" || fileResponse.getStatusCode() == "201")) {
         var fileContent = fileResponse.getBody(); // Get the response body directly                     

                   var attachment = new GlideSysAttachment();
                   // var agr = attachment.write(pdf,fileName, 'text/csv', fileContent);
                    //var agr = attachment.write(pdf, fileName, 'application/vnd.ms-excel', fileContent);
                    var agr = attachment.write(pdf, fileName, 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', fileContent);
 
}
Thanks in advance! 
Please help me to resolve this issue ASAP, its urgent.
1 REPLY 1

Ankur Bawiskar
Tera Patron
Tera Patron

@Krutika Kulkar1 

are you getting the base64 encoded data from the API response?

are you in global scope or scoped app?

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