Skip to content

Evaluate how much the fields in a table is used. Outputs the percent of each field within the given query #1583

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions Script Includes/evaluate-how-much-the-fields-is-used
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
function calculatePercentUsed(table, field, time){

var countAll = new GlideAggregate(table);
if (time){
countAll.addEncodedQuery(time);
}
countAll.addAggregate('COUNT');
countAll.query();
var allRecords = 0;
if (countAll.next()){
allRecords = countAll.getAggregate('COUNT');
gs.info('All records [' + table + ']: ' + allRecords);

}
var arrayFields = field.split(',');
for (var i=0; i<arrayFields.length; i++){

var countEmpty = new GlideAggregate(table);
countEmpty.addAggregate('COUNT');
countEmpty.addEncodedQuery(arrayFields[i] + 'ISNOTEMPTY');
if (time){
countEmpty.addEncodedQuery(time);
}
countEmpty.query();
var emptyRecords = 0;
if (countEmpty.next()){
emptyRecords = countEmpty.getAggregate('COUNT');
gs.info('Records using field [' + arrayFields[i] + ']: ' + emptyRecords);
}

if (allRecords != 0){
var percentUsed = parseFloat(emptyRecords/allRecords);
gs.info('Percent used: ' + (percentUsed*100).toFixed(2) );
}

}
if (allRecords == 0){
gs.info('No records found');
}

}
Loading