|
6 | 6 | // No Training Required: Analyzes existing data without ML |
7 | 7 | // ======================================== |
8 | 8 |
|
| 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 | + |
9 | 17 | (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) |
11 | 19 | 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()); |
35 | 25 | } |
36 | | - var field = new GlideRecord('sys_dictionary'); |
37 | | - field.addQuery('name', 'IN', tables.join(',')); |
38 | | - field.query(); |
39 | | - |
40 | 26 | } |
| 27 | + // printAllFields('incident'); |
41 | 28 |
|
42 | | - printAllFields('incident'); |
43 | | - // Helper: check if field exists in table hierarchy |
| 29 | + // Helper: check if field exists in table hierarchy (simplified) |
44 | 30 | 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(); |
| 31 | + var gr = new GlideRecord(tableName); |
| 32 | + return gr.isValidField(fieldName); |
| 33 | + } |
| 34 | + |
| 35 | + // Print table ancestors (if SNC.TableEditor available) |
| 36 | + if (typeof SNC !== 'undefined' && SNC.TableEditor && SNC.TableEditor.getTableAncestors) { |
| 37 | + gs.info('Ancestors of incident: ' + SNC.TableEditor.getTableAncestors('incident')); |
74 | 38 | } |
75 | 39 |
|
76 | 40 | // ============================================ |
|
339 | 303 | total = parseInt(totalGr.getAggregate('COUNT')); |
340 | 304 | } |
341 | 305 |
|
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 | | - } |
| 306 | + // ...existing code... |
374 | 307 |
|
375 | 308 | // Check each field, skip if not present |
376 | 309 | for (var f = 0; f < config.keyFields.length; f++) { |
|
0 commit comments