Skip to content

Commit 86a1473

Browse files
authored
Create top10AttachmentBySize.js
Code to get the top 10 largest attachment in the instance by size
1 parent e7aa2f9 commit 86a1473

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Create a GlideRecord object to query the 'sys_attachment' table
2+
var grAttachments = new GlideRecord('sys_attachment');
3+
4+
// Sort the results by 'size_bytes' in descending order to get the largest attachments first
5+
grAttachments.orderByDesc('size_bytes');
6+
7+
// Limit the query to return only the top 10 records
8+
grAttachments.setLimit(10);
9+
10+
// Execute the query
11+
grAttachments.query();
12+
13+
// Log a header message to indicate the start of the output
14+
gs.info('Top 10 largest attachments:');
15+
16+
// Loop through each record returned by the query
17+
while (grAttachments.next()) {
18+
// Convert the size from bytes to megabytes and round to 2 decimal places
19+
var sizeMB = (grAttachments.size_bytes / (1024 * 1024)).toFixed(2);
20+
21+
// Log the file name, size in MB, and the table the attachment belongs to
22+
gs.info(
23+
' - ' + grAttachments.getDisplayValue('file_name') +
24+
' | Size: ' + sizeMB + ' MB' +
25+
' | Table: ' + grAttachments.getDisplayValue('table_name')
26+
);
27+
}

0 commit comments

Comments
 (0)