-
Notifications
You must be signed in to change notification settings - Fork 919
Expand file tree
/
Copy pathscript.js
More file actions
106 lines (89 loc) · 3.56 KB
/
script.js
File metadata and controls
106 lines (89 loc) · 3.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// Virtual Agent Topic Coverage Report
// Analyzes VA topic configuration health and usage patterns
var daysBack = 30; // Analyze topic usage from the past 30 days
// Calculate date range for usage analysis
var startDate = new GlideDateTime();
startDate.addDaysLocalTime(-daysBack);
gs.info('=== Virtual Agent Topic Coverage Report ===');
gs.info('Analyzing topics and usage from: ' + startDate.getDisplayValue());
// Get all VA topics
var topicGr = new GlideRecord('sys_cs_topic');
if (!topicGr.isValid()) {
gs.warn('Table sys_cs_topic not found. Virtual Agent may not be installed.');
} else {
topicGr.query();
var totalTopics = topicGr.getRowCount();
gs.info('Total Topics: ' + totalTopics);
var inactiveTopics = [];
var unpublishedTopics = [];
var zeroUsageTopics = [];
var topicUsage = {};
// Auto-detect conversation table field name
var convGr = new GlideRecord('sys_cs_conversation');
var topicField = null;
if (convGr.isValid()) {
topicField = convGr.isValidField('topic') ? 'topic' :
(convGr.isValidField('selected_topic') ? 'selected_topic' : null);
}
while (topicGr.next()) {
var topicId = topicGr.getUniqueValue();
var topicName = topicGr.getValue('name');
var isActive = topicGr.getValue('active') == 'true' || topicGr.getValue('active') == '1';
var isPublished = topicGr.getValue('published') == 'true' || topicGr.getValue('published') == '1';
// Track inactive topics
if (!isActive) {
inactiveTopics.push(topicName);
}
// Track unpublished topics
if (!isPublished) {
unpublishedTopics.push(topicName);
}
// Count conversations for this topic (if conversation table exists)
var conversationCount = 0;
if (topicField) {
var convCountGr = new GlideAggregate('sys_cs_conversation');
convCountGr.addQuery(topicField, topicId);
convCountGr.addQuery('sys_created_on', '>=', startDate);
convCountGr.addAggregate('COUNT');
convCountGr.query();
if (convCountGr.next()) {
conversationCount = parseInt(convCountGr.getAggregate('COUNT')) || 0;
}
}
topicUsage[topicName] = conversationCount;
// Track topics with zero usage
if (isActive && isPublished && conversationCount === 0) {
zeroUsageTopics.push(topicName);
}
}
// Display results
gs.info('\n=== Inactive Topics ===');
if (inactiveTopics.length > 0) {
for (var i = 0; i < inactiveTopics.length; i++) {
gs.info((i + 1) + '. ' + inactiveTopics[i]);
}
} else {
gs.info('No inactive topics found');
}
gs.info('\n=== Unpublished Topics ===');
if (unpublishedTopics.length > 0) {
for (var j = 0; j < unpublishedTopics.length; j++) {
gs.info((j + 1) + '. ' + unpublishedTopics[j]);
}
} else {
gs.info('No unpublished topics found');
}
gs.info('\n=== Topics with Zero Usage (Active & Published) ===');
if (zeroUsageTopics.length > 0) {
for (var k = 0; k < zeroUsageTopics.length; k++) {
gs.info((k + 1) + '. ' + zeroUsageTopics[k]);
}
} else {
if (topicField) {
gs.info('All active & published topics have been used');
} else {
gs.info('Cannot analyze usage - conversation table not available');
}
}
}
gs.info('\n=== Analysis Complete ===');