Skip to content

Commit 2bf7d2a

Browse files
authored
simplified (#2531)
Updates look good so far! Thanks for incorporating the proposed optimizations!
1 parent efc5be3 commit 2bf7d2a

File tree

1 file changed

+24
-90
lines changed

1 file changed

+24
-90
lines changed

Specialized Areas/Predictive Intelligence/Training Data Preparer/Incident Table/analyze_incident_data_training_quality.js

Lines changed: 24 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -6,71 +6,36 @@
66
// No Training Required: Analyzes existing data without ML
77
// ========================================
88

9+
// ========================================
10+
// PI Training Data Quality Analyzer (Simplified)
11+
// ========================================
12+
// Purpose: Analyze incident data quality for Predictive Intelligence training
13+
// Use Case: Identify data quality issues before training ML models
14+
// No Training Required: Analyzes existing data without ML
15+
// ========================================
16+
917
(function analyzeTrainingDataQuality() {
10-
// Print all fields that exist on the incident table and its parents
18+
// Print all fields that exist on the incident table and its parents (simplified)
1119
function printAllFields(tableName) {
12-
var tables = [tableName];
13-
var currentTable = tableName;
14-
while (currentTable) {
15-
var tableRec = new GlideRecord('sys_db_object');
16-
tableRec.addQuery('name', currentTable);
17-
tableRec.query();
18-
if (tableRec.next()) {
19-
var parentSysId = tableRec.getValue('super_class');
20-
if (parentSysId && parentSysId != '') {
21-
var parentRec = new GlideRecord('sys_db_object');
22-
if (parentRec.get(parentSysId)) {
23-
var parentName = parentRec.getValue('name');
24-
tables.push(parentName);
25-
currentTable = parentName;
26-
} else {
27-
currentTable = null;
28-
}
29-
} else {
30-
currentTable = null;
31-
}
32-
} else {
33-
currentTable = null;
34-
}
20+
var gr = new GlideRecord(tableName);
21+
var elements = gr.getElements();
22+
gs.info('Fields for table: ' + tableName);
23+
for (var i = 0; i < elements.size(); i++) {
24+
gs.info(elements.get(i).getName());
3525
}
36-
var field = new GlideRecord('sys_dictionary');
37-
field.addQuery('name', 'IN', tables.join(','));
38-
field.query();
39-
4026
}
4127

4228
printAllFields('incident');
43-
// Helper: check if field exists in table hierarchy
29+
30+
// Helper: check if field exists in table hierarchy (simplified)
4431
function fieldExists(tableName, fieldName) {
45-
var tables = [tableName];
46-
var currentTable = tableName;
47-
while (currentTable) {
48-
var tableRec = new GlideRecord('sys_db_object');
49-
tableRec.addQuery('name', currentTable);
50-
tableRec.query();
51-
if (tableRec.next()) {
52-
var parentSysId = tableRec.getValue('super_class');
53-
if (parentSysId && parentSysId != '') {
54-
var parentRec = new GlideRecord('sys_db_object');
55-
if (parentRec.get(parentSysId)) {
56-
var parentName = parentRec.getValue('name');
57-
tables.push(parentName);
58-
currentTable = parentName;
59-
} else {
60-
currentTable = null;
61-
}
62-
} else {
63-
currentTable = null;
64-
}
65-
} else {
66-
currentTable = null;
67-
}
68-
}
69-
var field = new GlideRecord('sys_dictionary');
70-
field.addQuery('element', fieldName);
71-
field.addQuery('name', 'IN', tables.join(','));
72-
field.query();
73-
return field.hasNext();
32+
var gr = new GlideRecord(tableName);
33+
return gr.isValidField(fieldName);
34+
}
35+
36+
// Print table ancestors (if SNC.TableEditor available)
37+
if (typeof SNC !== 'undefined' && SNC.TableEditor && SNC.TableEditor.getTableAncestors) {
38+
gs.info('Ancestors of incident: ' + SNC.TableEditor.getTableAncestors('incident'));
7439
}
7540

7641
// ============================================
@@ -339,38 +304,7 @@
339304
total = parseInt(totalGr.getAggregate('COUNT'));
340305
}
341306

342-
// Helper: check if field exists in table hierarchy
343-
function fieldExists(tableName, fieldName) {
344-
var tables = [tableName];
345-
var currentTable = tableName;
346-
while (currentTable) {
347-
var tableRec = new GlideRecord('sys_db_object');
348-
tableRec.addQuery('name', currentTable);
349-
tableRec.query();
350-
if (tableRec.next()) {
351-
var parentSysId = tableRec.getValue('super_class');
352-
if (parentSysId && parentSysId != '') {
353-
var parentRec = new GlideRecord('sys_db_object');
354-
if (parentRec.get(parentSysId)) {
355-
var parentName = parentRec.getValue('name');
356-
tables.push(parentName);
357-
currentTable = parentName;
358-
} else {
359-
currentTable = null;
360-
}
361-
} else {
362-
currentTable = null;
363-
}
364-
} else {
365-
currentTable = null;
366-
}
367-
}
368-
var field = new GlideRecord('sys_dictionary');
369-
field.addQuery('element', fieldName);
370-
field.addQuery('name', 'IN', tables.join(','));
371-
field.query();
372-
return field.hasNext();
373-
}
307+
// ...existing code...
374308

375309
// Check each field, skip if not present
376310
for (var f = 0; f < config.keyFields.length; f++) {

0 commit comments

Comments
 (0)