Skip to content

Commit b1f1f7f

Browse files
authored
Create evaluate-how-much-the-fields-is-used
Use to evaluate how much the fields in a table is used. Outputs the percent of each field within the given query. This script include can be called from Business Rule
1 parent 0e05c51 commit b1f1f7f

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
function calculatePercentUsed(table, field, time){
2+
3+
var countAll = new GlideAggregate(table);
4+
if (time){
5+
countAll.addEncodedQuery(time);
6+
}
7+
countAll.addAggregate('COUNT');
8+
countAll.query();
9+
var allRecords = 0;
10+
if (countAll.next()){
11+
allRecords = countAll.getAggregate('COUNT');
12+
gs.info('All records [' + table + ']: ' + allRecords);
13+
14+
}
15+
var arrayFields = field.split(',');
16+
for (var i=0; i<arrayFields.length; i++){
17+
18+
var countEmpty = new GlideAggregate(table);
19+
countEmpty.addAggregate('COUNT');
20+
countEmpty.addEncodedQuery(arrayFields[i] + 'ISNOTEMPTY');
21+
if (time){
22+
countEmpty.addEncodedQuery(time);
23+
}
24+
countEmpty.query();
25+
var emptyRecords = 0;
26+
if (countEmpty.next()){
27+
emptyRecords = countEmpty.getAggregate('COUNT');
28+
gs.info('Records using field [' + arrayFields[i] + ']: ' + emptyRecords);
29+
}
30+
31+
if (allRecords != 0){
32+
var percentUsed = parseFloat(emptyRecords/allRecords);
33+
gs.info('Percent used: ' + (percentUsed*100).toFixed(2) );
34+
}
35+
36+
}
37+
if (allRecords == 0){
38+
gs.info('No records found');
39+
}
40+
41+
}

0 commit comments

Comments
 (0)