Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Table Size Analysis Script

This script checks the number of records in selected ServiceNow tables and shows how many were created in the last 30 days.

## Tables Checked
- `task`
- `cmdb_ci`
- `sc_cat_item`

## What It Does
- Logs the start of the analysis.
- Counts total records in each table.
- Counts records created in the last 30 days.
- Logs both counts to the system log.

## How to Use
1. Add or remove table names in the `tablesToCheck` list.
2. Run the script in a background script or scheduled job.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// === TABLE SIZE ANALYSIS SCRIPT ===
// Log the start of the analysis
gs.info('=== TABLE SIZE ANALYSIS ===');

// Define the list of tables to analyze
var tablesToCheck = ['task', 'cmdb_ci', 'sc_cat_item'];

// Loop through each table in the list
for (var i = 0; i < tablesToCheck.length; i++) {
var tableName = tablesToCheck[i]; // Get current table name

// Create a GlideAggregate object to count total records in the table
var grCount = new GlideAggregate(tableName);
grCount.addAggregate('COUNT'); // Add COUNT aggregate
grCount.query(); // Execute the query

// If the query returns a result
if (grCount.next()) {
var recordCount = grCount.getAggregate('COUNT'); // Get total record count
gs.info('Table: ' + tableName + ' | Record count: ' + recordCount); // Log the count

// Optional: Analyze growth by checking records created in the last 30 days
var grRecent = new GlideAggregate(tableName);
grRecent.addAggregate('COUNT'); // Add COUNT aggregate
grRecent.addQuery('sys_created_on', '>=', gs.daysAgo(30)); // Filter records created in last 30 days
grRecent.query(); // Execute the query

// If the query returns a result
if (grRecent.next()) {
var recentCount = grRecent.getAggregate('COUNT'); // Get count of recent records
gs.info(' - Records created last 30 days: ' + recentCount); // Log the recent count
}
}
}
Loading