- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2025 01:59 PM
Hello comunity, the last few days I've been developing a Script Include that gets the info of many records and exports this info as an excel spreadsheet.
I use a string variable called recData, it contains a large xml that builds the spreadsheet. For each column a line is created and added to this string.
I use GlideSysAttachment.write() to create the spreadsheet. My problem is that the variable recData always exceeds the string limit.
Is there a way to use more than one string and them put them together? or maybe use an array of string and use that as a parameter to the write() function?
I'd like to build a single excel spreadsheet, please enlighten me with your knowledge.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2025 12:10 AM
Hi @izaquenogue
You can try with these steps
Use an Array and Join Method:
Instead of appending large XML content to a single string, store each row or segment in an array.
Use .join('\n') to merge all entries before writing to GlideSysAttachment.
var recDataArray = [];
recDataArray.push('<?xml version="1.0" encoding="UTF-8"?>');
recDataArray.push('<Workbook>');
recDataArray.push('<Row><Cell>Data1</Cell></Row>');
recDataArray.push('</Workbook>');
var finalData = recDataArray.join('\n');
GlideSysAttachment.write(current, "Export.xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", finalData);
Use StringBuilder (gs.getProperty) for Efficient Concatenation:
ServiceNow provides gs.getProperty('sys_property') for handling large strings effectively.
Use a property to store segments, append them dynamically, and retrieve the final XML.
Write Data in Chunks Using GlideSysAttachment:
Instead of writing the entire XML string at once, try writing incrementally in chunks using multiple calls to GlideSysAttachment.write().
This helps ServiceNow manage memory efficiently.
Alternative Approach (Using GlideExcelBuilder)
If you're exporting structured data, consider using GlideExcelBuilder instead of manually generating XML.
It simplifies spreadsheet creation and avoids excessive string concatenation.
Stay awesome,
Roshnee Dash
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2025 12:10 AM
Hi @izaquenogue
You can try with these steps
Use an Array and Join Method:
Instead of appending large XML content to a single string, store each row or segment in an array.
Use .join('\n') to merge all entries before writing to GlideSysAttachment.
var recDataArray = [];
recDataArray.push('<?xml version="1.0" encoding="UTF-8"?>');
recDataArray.push('<Workbook>');
recDataArray.push('<Row><Cell>Data1</Cell></Row>');
recDataArray.push('</Workbook>');
var finalData = recDataArray.join('\n');
GlideSysAttachment.write(current, "Export.xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", finalData);
Use StringBuilder (gs.getProperty) for Efficient Concatenation:
ServiceNow provides gs.getProperty('sys_property') for handling large strings effectively.
Use a property to store segments, append them dynamically, and retrieve the final XML.
Write Data in Chunks Using GlideSysAttachment:
Instead of writing the entire XML string at once, try writing incrementally in chunks using multiple calls to GlideSysAttachment.write().
This helps ServiceNow manage memory efficiently.
Alternative Approach (Using GlideExcelBuilder)
If you're exporting structured data, consider using GlideExcelBuilder instead of manually generating XML.
It simplifies spreadsheet creation and avoids excessive string concatenation.
Stay awesome,
Roshnee Dash
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2025 05:09 AM
Hello, Roshnee. Thank you for your answer!
In the end, I decided to use the chunking method with the array and join method. I didn't find anything about GlideExcelBuilder, could you direct me to the docs?
Again, thank you for your answer!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2025 09:04 AM
Hi @izaquenogue
For GlideExcelBuilder i have only basic knowledge.
If you found my solution helpful or if it resolved your issue, please consider marking it as 'Helpful' or 'Accept Solution' and closing the thread. Thank you!
Stay awesome,
Roshnee Dash