File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed
Server-Side Components/Background Scripts/Get top 10 largest attachment Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments