Need Help in Scheduled report
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-05-2024 05:38 AM
We have a requirment where in report we have records more than 1000. And in the system Property for pdf format the row limit is set to 1000. We want to execute the scheduled report in multiple batches of 1000 without changing the system property limit.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-05-2024 06:11 AM
Hi @sirisha27
You can achieve this by creating a new scheduled report. You can use a Script Include to process the report data in chunks of 1000 rows. This involves using pagination techniques to break the result set into smaller parts.
Use GlideRecord to fetch the data in chunks of 1000. For each batch, generate a separate report or export the result to PDF.
I hope my answer helps you to resolve your issue, if yes please mark my answer helpful and correct.
thank you
Rajesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-05-2024 06:16 AM
Could you please share any sample script to export pdf file. It would be very helpful for us.
Thank you in advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-06-2024 06:35 AM
hi @sirisha27
Have you tried any script yet? if yes - share with us, will help you there, otherwise you can refer bellow sample script:
var batchSize = 1000;
var totalRecordsProcessed = 0;
var tableName = 'incident'; // Replace with your target table name
var lastSysId = ''; // Initialize for pagination based on sys_id
while (true) {
var gr = new GlideRecord(tableName);
// Apply filter to continue from the last record processed
if (lastSysId) {
gr.addQuery('sys_id', '>', lastSysId); // Filter records that have a sys_id greater than the last processed
}
gr.setLimit(batchSize); // Limit to 1000 records per batch
gr.orderBy('sys_id'); // Ensure results are ordered by sys_id (or another field if needed)
gr.query(); // Run the query
if (!gr.hasNext()) {
break; // Exit if no more records are available
}
var records = [];
var currentBatchCount = 0; // Count for the current batch
while (gr.next()) {
// Process the records (example: push the 'number' field to the list)
records.push(gr.getValue('number')); // Add 'number' field (or any other field you want)
lastSysId = gr.getValue('sys_id'); // Track the last processed sys_id to ensure pagination
currentBatchCount++;
}
if (currentBatchCount > 0) {
// Generate and save the PDF only if we have records in this batch
generateAndSavePDF(records);
}
// Update the total records processed after each batch
totalRecordsProcessed += currentBatchCount;
// Log the number of records processed in the current batch for tracking purposes
gs.info("Batch processed. Total records so far: " + totalRecordsProcessed);
}
// Function to generate and save PDF (this is a placeholder logic)
function generateAndSavePDF(records) {
// Placeholder logic to generate a report based on 'records'
// For example, create a report record, generate PDF, and attach/save it
var report = new GlideRecord('sys_report'); // Assuming you're working with a report table (custom or default)
report.initialize();
report.setValue('name', 'Your custom report name');
report.setValue('description', 'Generated for batch processing');
report.insert();
gs.info("PDF generated for this batch: " + records.length + " records.");
}
I hope my answer helps you to resolve your issue, if yes please mark my answer helpful and correct.
thank you
Rajesh