Generete Excel Sheet Using Script

balochfarha
Mega Contributor

Hello Everyone , I want to generate an excel file xlsx with dropdowns(data validation) feature is it possible in Servicenow Scripting?
Thankyou,

 

1 ACCEPTED SOLUTION

Michelle Bryant
ServiceNow Employee
ServiceNow Employee

Hi @balochfarha 

 

directly generating a true .xlsx file with dropdowns using only ServiceNow scripting is not supported. Here's why:

  • ServiceNow scripting can generate .xls-like files using SpreadsheetML (Excel XML format), but this is not true .xlsx and lacks support for advanced features like dropdowns.
  • Attempts to script .xlsx output often result in corrupted or unreadable files.

There are workarounds you can try though: 

 

1. Use SpreadsheetML (XML-based .xls)

You can manually construct an XML structure that mimics Excel formatting. This allows basic styling (like bold headers) but not dropdowns. Here's a simplified example from a ServiceNow Community post:

MichelleBryant_0-1756408151364.png

 

This creates a basic .xls file, but again, no dropdowns.

2. Use IntegrationHub or MID Server

To generate a proper .xlsx file with dropdowns:

  • Use IntegrationHub to call an external script or API (e.g., Python, PowerShell, or Excel macro) that builds the file.
  • Then attach the file back to a record in ServiceNow using GlideSysAttachment.

This method gives you full Excel capabilities, including:

  • Data validation (dropdowns)
  • Conditional formatting
  • Formulas and charts

 

 

 

Code that you can copy if needed:

var xml = "";

xml += "<workbook xmlns='urn:schemas-microsoft-com:office:spreadsheet'>";</workbook xmlns='urn:schemas-microsoft-com:office:spreadsheet'>

xml += "<worksheet ss:name='data'>";</worksheet ss:name='data'>

xml += "";

 

xml += "<data ss:type='string'>Name</data ss:type='string'>";

xml += "<data ss:type='string'>Mish</data ss:type='string'>";

xml += "

";

 

 

var gr = new GlideRecord('incident');

gr.get('sys_id');

var attachment = new GlideSysAttachment();

attachment.write(gr, "example.xls", "application/vnd.ms-excel", xml);

 

Best - Mish Bryant

View solution in original post

2 REPLIES 2

kaushal_snow
Mega Sage

Hi @balochfarha ,

 

One workaround uses SpreadsheetML (Excel XML format) essentially .xls by constructing XML manually in script, then attaching it via GlideSysAttachment. This does not generate true .xlsx files and can’t support advanced Excel features like dropdowns and most common issues are when trying to export .xlsx via script, users face corruption and invalid format errors even before opening the file.


So conclusion is, Directly scripting an .xlsx with dropdowns inside ServiceNow isn't supported. The most effective route is to leverage external tooling or IntegrationHub/MID Server processing to build the file, then bring it into the platform.

 

If you found my response helpful, please mark it as ‘Accept as Solution’ and ‘Helpful’. This helps other community members find the right answer more easily and supports the community.

 

 

Thanks and Regards,
Kaushal Kumar Jha - ServiceNow Consultant - Lets connect on Linkedin: https://www.linkedin.com/in/kaushalkrjha/

Michelle Bryant
ServiceNow Employee
ServiceNow Employee

Hi @balochfarha 

 

directly generating a true .xlsx file with dropdowns using only ServiceNow scripting is not supported. Here's why:

  • ServiceNow scripting can generate .xls-like files using SpreadsheetML (Excel XML format), but this is not true .xlsx and lacks support for advanced features like dropdowns.
  • Attempts to script .xlsx output often result in corrupted or unreadable files.

There are workarounds you can try though: 

 

1. Use SpreadsheetML (XML-based .xls)

You can manually construct an XML structure that mimics Excel formatting. This allows basic styling (like bold headers) but not dropdowns. Here's a simplified example from a ServiceNow Community post:

MichelleBryant_0-1756408151364.png

 

This creates a basic .xls file, but again, no dropdowns.

2. Use IntegrationHub or MID Server

To generate a proper .xlsx file with dropdowns:

  • Use IntegrationHub to call an external script or API (e.g., Python, PowerShell, or Excel macro) that builds the file.
  • Then attach the file back to a record in ServiceNow using GlideSysAttachment.

This method gives you full Excel capabilities, including:

  • Data validation (dropdowns)
  • Conditional formatting
  • Formulas and charts

 

 

 

Code that you can copy if needed:

var xml = "";

xml += "<workbook xmlns='urn:schemas-microsoft-com:office:spreadsheet'>";</workbook xmlns='urn:schemas-microsoft-com:office:spreadsheet'>

xml += "<worksheet ss:name='data'>";</worksheet ss:name='data'>

xml += "";

 

xml += "<data ss:type='string'>Name</data ss:type='string'>";

xml += "<data ss:type='string'>Mish</data ss:type='string'>";

xml += "

";

 

 

var gr = new GlideRecord('incident');

gr.get('sys_id');

var attachment = new GlideSysAttachment();

attachment.write(gr, "example.xls", "application/vnd.ms-excel", xml);

 

Best - Mish Bryant