Not able to open attached excel file to a record (xlsx format)

Tanwir Singh11
Tera Expert

Hi All,

I am creating an excel and attaching to a record.

I am using the below code to attach the file:

var grRec = new GlideRecord("sc_task");
    grRec.addQuery("sys_id", current.sys_id + "");
    grRec.query();
    if (grRec.next()) {
        var grAttachment = new GlideSysAttachment();
        grAttachment.write(grRec, fileName, 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', csvData);
    }

 

It works perfectly for application/csv but not for xlsx format and I need the .xlsx format. The file gets created and attached but when I try to open it, it says the file is corrupted.

Could anyone tell me what am i doing wrong here, please?

 

Thanks!!!

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

it's not straight forward for xlsx file and it won't work

Either keep it csv or else you would require custom solution to create xlsx file and attach to record

Regards
Ankur

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

View solution in original post

9 REPLIES 9

Tanwir Singh11
Tera Expert

hey @Ankur Bawiskar , @Chuck Tomasi , @Robert Fedoruk 

Could you guys please help?

Ankita Sarkar
Tera Guru

Hi,

Please have a look at this ServiceNow KB article which might help you.

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0752391

 

Regards,

Ankita Sarkar

hey,

This is not a REST call. 

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

it's not straight forward for xlsx file and it won't work

Either keep it csv or else you would require custom solution to create xlsx file and attach to record

Regards
Ankur

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