- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-09-2025 01:59 AM
1. Is it possible to find out how large (KB/MB/GB) a table is?
2. If so, can you also find out for a filtered table?
So you would have a table with 500K record, know the size, filter the table to 200k recrods. Can you then scale it or display it correctly?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-09-2025 04:19 AM - edited ‎04-10-2025 02:40 AM
Hello Meloper,
You can use the following script to calculate the size of the data in a table. Just change the table name as needed.
function getFieldNames(table) {
var fieldNames = [];
var gr = new GlideRecord(table);
gr.initialize();
for (var field in gr) {
fieldNames.push(field);
}
return fieldNames;
}
var table = 'incident';
var size = 0, count = 0;
var fieldNames = getFieldNames(table);
var gr = new GlideRecord(table);
gr.setLimit(10000);
gr.query();
while (gr.next()) {
fieldNames.forEach(field => {
size += gr[field].toString().length;
});
count++;
}
gs.print(gs.getMessage('{0} records with a total size of {1} bytes', [count, size]));
Example output:
103.0 records with a total size of 52582.0 bytes
This calculation takes time so I have set a hard limit of 10k records to analyze.
If your table has more than 10k records you need to multiply the result accordingly, e.g. if the script returns 5 MByte for 10k records but you have 500k total records you have to do 5 MByte * 50 = 250 MByte.
Please also note that the actual table size is probably a bit larger than that due to meta data and other overhead, like some unusual Unicode characters that can take up to 4 bytes per character.
Regards,
Robert
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-10-2025 02:19 AM
Hello @Meloper
For regular text that uses the Latin alphabet (like English) 1 character is indeed 1 byte. But more exotic Unicode characters can require up to 4 bytes:
So the code that I provided is actually a bit simplified and assumes that 1 character = 1 byte, which should give you a rough idea.
For reference fields, the code uses the length of the sys_id (always 32 characters) and not the display value, because that display value is not actually stored in the table we are analyzing but the table that the reference field points to.
Regards,
Robert
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-09-2025 02:37 AM
It would be great if you could share screenshot containing sample result for incident so that it helps members
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-09-2025 04:08 AM
Hello @Meloper
Kindly go through the below link once that might help you.
Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this question to solved bucket.
Regards,
Prathamesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-09-2025 04:19 AM - edited ‎04-10-2025 02:40 AM
Hello Meloper,
You can use the following script to calculate the size of the data in a table. Just change the table name as needed.
function getFieldNames(table) {
var fieldNames = [];
var gr = new GlideRecord(table);
gr.initialize();
for (var field in gr) {
fieldNames.push(field);
}
return fieldNames;
}
var table = 'incident';
var size = 0, count = 0;
var fieldNames = getFieldNames(table);
var gr = new GlideRecord(table);
gr.setLimit(10000);
gr.query();
while (gr.next()) {
fieldNames.forEach(field => {
size += gr[field].toString().length;
});
count++;
}
gs.print(gs.getMessage('{0} records with a total size of {1} bytes', [count, size]));
Example output:
103.0 records with a total size of 52582.0 bytes
This calculation takes time so I have set a hard limit of 10k records to analyze.
If your table has more than 10k records you need to multiply the result accordingly, e.g. if the script returns 5 MByte for 10k records but you have 500k total records you have to do 5 MByte * 50 = 250 MByte.
Please also note that the actual table size is probably a bit larger than that due to meta data and other overhead, like some unusual Unicode characters that can take up to 4 bytes per character.
Regards,
Robert
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-10-2025 01:17 AM
Wow, thanks, so 1 Char = 1 Byte?
is that true? Does it count the Display Value or the SysID for Ref Fields, and is it true that 1 Char is on Byte?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-10-2025 02:19 AM
Hello @Meloper
For regular text that uses the Latin alphabet (like English) 1 character is indeed 1 byte. But more exotic Unicode characters can require up to 4 bytes:
So the code that I provided is actually a bit simplified and assumes that 1 character = 1 byte, which should give you a rough idea.
For reference fields, the code uses the length of the sys_id (always 32 characters) and not the display value, because that display value is not actually stored in the table we are analyzing but the table that the reference field points to.
Regards,
Robert