Last active
July 15, 2021 19:46
-
-
Save swaters86/806b733f62a8391e07a3a5b42b4611a8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var ServiceNowData = Class.create(); | |
ServiceNowData.prototype = { | |
initialize : function(dryRun, table, encodedQuery, addedQueries, orderBy, fields) { | |
this.dryRun = dryRun; | |
this.table = table; | |
this.encodedQuery = encodedQuery; | |
this.addedQueries = addedQueries; | |
this.orderBy = orderBy; | |
this.fields = fields; | |
}, | |
getRecords : function() { | |
var gr = new GlideRecord(this.table); | |
gr.addEncodedQuery(this.encodedQuery); | |
gr.orderBy(this.orderBy); | |
gr.query(); | |
var records = ""; | |
while(gr.next()){ | |
records += "{\"ticket_number\": \"" + gr.getValue('number') + "\", \"sys_id\": \"" + gr.getValue('sys_id') + "\"},\n"; | |
} | |
return records; | |
}, | |
getCount : function() { | |
var ga = new GlideAggregate(this.table); | |
ga.addEncodedQuery(this.encodedQuery); | |
ga.addAggregate('COUNT'); | |
ga.query(); | |
var totalRecords = 0; | |
if (ga.next()) { | |
totalRecords = ga.getAggregate('COUNT'); | |
} | |
return totalRecords; | |
}, | |
type: 'ServiceNowData' | |
}; | |
var snowQuery = '^cmdb_ci.asset.beneficiary%3Dde89c14c1b8fc850f24d415fad4bcb11'; | |
//var snowQuery = 'active=true^short_descriptionLIKEchangegear'; | |
var tables = ['incident', 'incident_task', 'problem', 'problem_task', 'change_request', 'change_task', 'sc_request', 'sc_req_item', 'sc_task']; | |
var table = ""; | |
var dbTable = ""; | |
for(i=0;i<tables.length;i++) { | |
dbTable = ""; | |
tableObj = ""; | |
dbTable = tables[i]; | |
tableObj = new ServiceNowData(null, dbTable, snowQuery, null, 'name', null); | |
gs.print("\n Found " + tableObj.getCount() + " for table " + dbTable + ":\n" + tableObj.getRecords()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment