Scheduled email export of 45k+ contract records (updated last month) — worried about missed records,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
Hi all,
I have a custom table with around 45,000 contract records. The client uploads 10,000+ new records daily, so applying a static filter isn't really an option.
The requirement is: send a scheduled email export of all records that were updated in the last month.
I've already created a report and set it up to send via scheduled email, but I'm concerned that some records may be getting missed/truncated during the export due to the volume.
My questions:
- Is there a reliable way to schedule this export so no records get missed, given the table size and daily inserts?
- If a single export isn't reliable at this volume, what's the best way to split the data — for example, sending it in batches of 10,000 records across multiple Excel files in one scheduled email?
- Would this be better handled through a scheduled script (GlideRecord + attachment/email) rather than the standard report export, and if so, does anyone have an example approach for batching into multiple files?
Any guidance, best practices, or examples from those who've handled similar large recurring exports would be really helpful.
Thanks in advance!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
14m ago - last edited 14m ago
Hey @harshal001
With 10,000+ records being added daily, a "Last 30 Days" report could easily return several hundred thousand records. At that scale, scheduled report exports may run into execution timeouts, attachment size limits, or Excel row limitations, depending on your instance configuration.
A more reliable approach is to use a Scheduled Script Execution and export the data in batches.
Script:
(function() {
var BATCH_SIZE = 10000;
var offset = 0;
var batchNo = 1;
while (true) {
var gr = new GlideRecord('u_contract');
gr.addQuery('sys_updated_on', '>=', 'javascript:gs.daysAgoStart(30)');
gr.orderBy('sys_updated_on');
gr.chooseWindow(offset, offset + BATCH_SIZE);
gr.query();
if (!gr.hasNext())
break;
var csv = "Number,Name,Updated On\n";
while (gr.next()) {
csv += [
gr.getValue('number'),
gr.getDisplayValue('u_name'),
gr.getDisplayValue('sys_updated_on')
].join(",") + "\n";
}
var attachment = new GlideSysAttachment();
attachment.write(
current,
"Contracts_Batch_" + batchNo + ".csv",
"text/csv",
csv
);
offset += BATCH_SIZE;
batchNo++;
}
})();
For sending the files:
- Generate one CSV per batch (for example, 10,000 records each).
- Attach all generated CSV files to the same record (or a staging record).
- Send a notification/email that includes all attachments.
********************************************************************************************************************************
If this response helps, please mark it as Accept as Solution and Helpful.
Doing so helps others in the community and encourages me to keep contributing.
Regards
Vaishali Singh
Servicenow Developer
Linkedin - https://www.linkedin.com/in/vaishali-singh-2273361bb
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
58 seconds ago
Hi @vaishali231 , Client wanted xlsx file format.