Calculate specific table attachments size from sys_attachment table
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2018 11:44 AM
Hi,
I need to calculate total attachments size of hr table from sys_attachment table ? Can anyone help me with the script
var gr = new GlideRecord('sys_attachment');
gr.addQuery('table_name','hr_case');
gr.Query();
var totalSize=0;
while(gr.next()) {
totalSize=parseInt(gr.size_bytes);
}
gs.print(totalSize);
Labels:
- Labels:
-
Scripting and Coding
5 REPLIES 5

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2020 06:37 AM
Total sys_attachment size for all tables:
(function(){
function convertBytes(bytes) {
var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
if (bytes == 0) return '0 Byte';
var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)),10);
return Math.round(bytes / Math.pow(1024, i), 2) + ' ' + sizes[i];
}
var r = 0;
var att = new GlideAggregate('sys_attachment');
att.addAggregate('SUM', 'size_bytes');
att.query();
while (att.next()) {
r += parseInt(att.getAggregate('SUM','size_bytes'),10);
}
gs.print(convertBytes(r));
})();
Total sys_attachment size for hr_case:
(function(){
function convertBytes(bytes) {
var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
if (bytes == 0) return '0 Byte';
var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)),10);
return Math.round(bytes / Math.pow(1024, i), 2) + ' ' + sizes[i];
}
var r = 0;
var att = new GlideAggregate('sys_attachment');
att.addAggregate('SUM', 'size_bytes');
att.addQuery('table_name', 'hr_case');
att.query();
while (att.next()) {
r += parseInt(att.getAggregate('SUM','size_bytes'),10);
}
gs.print(convertBytes(r));
})();