Skip to content

Commit ef1d3fd

Browse files
authored
Virtual agent topic coverage report (#2266)
* Add Virtual Agent Topic Coverage Report script This script analyzes the health and usage patterns of Virtual Agent topics over the past 30 days, identifying inactive, unpublished, and zero usage topics. * Add files via upload added readme
1 parent d09071b commit ef1d3fd

File tree

2 files changed

+133
-0
lines changed
  • Server-Side Components/Background Scripts/Virtual Agent Topic Coverage Report

2 files changed

+133
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Virtual Agent Topic Coverage Report
2+
3+
A background script that analyzes Virtual Agent topic configuration health by identifying inactive, unpublished, or unused topics.
4+
5+
## Usage
6+
7+
1. Navigate to **System Definition → Scripts - Background**
8+
2. Copy and paste the script content
9+
3. (Optional) Modify `daysBack` variable to set the usage analysis timeframe (default: 30 days)
10+
4. Click "Run script"
11+
12+
## What It Does
13+
14+
The script:
15+
1. Queries all Virtual Agent topics in the system
16+
2. Checks each topic's active and published status
17+
3. Counts conversations per topic over the past 30 days (configurable)
18+
4. Displays inactive topics, unpublished topics, and zero-usage topics
19+
5. Helps identify topics that need attention before go-live or during health checks
20+
21+
## Report Categories
22+
23+
**Inactive Topics**: Topics where the "Active" checkbox is unchecked. These topics are disabled and won't respond to user inputs even if published.
24+
25+
**Unpublished Topics**: Topics where the "Published" checkbox is unchecked. These are draft topics not yet available to end users.
26+
27+
**Topics with Zero Usage**: Topics that are both active and published but have had no conversations in the specified timeframe. May indicate topics that need better training phrases or are not discoverable by users.
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
// Virtual Agent Topic Coverage Report
2+
// Analyzes VA topic configuration health and usage patterns
3+
4+
var daysBack = 30; // Analyze topic usage from the past 30 days
5+
6+
// Calculate date range for usage analysis
7+
var startDate = new GlideDateTime();
8+
startDate.addDaysLocalTime(-daysBack);
9+
10+
gs.info('=== Virtual Agent Topic Coverage Report ===');
11+
gs.info('Analyzing topics and usage from: ' + startDate.getDisplayValue());
12+
13+
// Get all VA topics
14+
var topicGr = new GlideRecord('sys_cs_topic');
15+
if (!topicGr.isValid()) {
16+
gs.warn('Table sys_cs_topic not found. Virtual Agent may not be installed.');
17+
} else {
18+
topicGr.query();
19+
20+
var totalTopics = topicGr.getRowCount();
21+
gs.info('Total Topics: ' + totalTopics);
22+
23+
var inactiveTopics = [];
24+
var unpublishedTopics = [];
25+
var zeroUsageTopics = [];
26+
var topicUsage = {};
27+
28+
// Auto-detect conversation table field name
29+
var convGr = new GlideRecord('sys_cs_conversation');
30+
var topicField = null;
31+
if (convGr.isValid()) {
32+
topicField = convGr.isValidField('topic') ? 'topic' :
33+
(convGr.isValidField('selected_topic') ? 'selected_topic' : null);
34+
}
35+
36+
while (topicGr.next()) {
37+
var topicId = topicGr.getUniqueValue();
38+
var topicName = topicGr.getValue('name');
39+
var isActive = topicGr.getValue('active') == 'true' || topicGr.getValue('active') == '1';
40+
var isPublished = topicGr.getValue('published') == 'true' || topicGr.getValue('published') == '1';
41+
42+
// Track inactive topics
43+
if (!isActive) {
44+
inactiveTopics.push(topicName);
45+
}
46+
47+
// Track unpublished topics
48+
if (!isPublished) {
49+
unpublishedTopics.push(topicName);
50+
}
51+
52+
// Count conversations for this topic (if conversation table exists)
53+
var conversationCount = 0;
54+
if (topicField) {
55+
var convCountGr = new GlideAggregate('sys_cs_conversation');
56+
convCountGr.addQuery(topicField, topicId);
57+
convCountGr.addQuery('sys_created_on', '>=', startDate);
58+
convCountGr.addAggregate('COUNT');
59+
convCountGr.query();
60+
if (convCountGr.next()) {
61+
conversationCount = parseInt(convCountGr.getAggregate('COUNT')) || 0;
62+
}
63+
}
64+
65+
topicUsage[topicName] = conversationCount;
66+
67+
// Track topics with zero usage
68+
if (isActive && isPublished && conversationCount === 0) {
69+
zeroUsageTopics.push(topicName);
70+
}
71+
}
72+
73+
// Display results
74+
gs.info('\n=== Inactive Topics ===');
75+
if (inactiveTopics.length > 0) {
76+
for (var i = 0; i < inactiveTopics.length; i++) {
77+
gs.info((i + 1) + '. ' + inactiveTopics[i]);
78+
}
79+
} else {
80+
gs.info('No inactive topics found');
81+
}
82+
83+
gs.info('\n=== Unpublished Topics ===');
84+
if (unpublishedTopics.length > 0) {
85+
for (var j = 0; j < unpublishedTopics.length; j++) {
86+
gs.info((j + 1) + '. ' + unpublishedTopics[j]);
87+
}
88+
} else {
89+
gs.info('No unpublished topics found');
90+
}
91+
92+
gs.info('\n=== Topics with Zero Usage (Active & Published) ===');
93+
if (zeroUsageTopics.length > 0) {
94+
for (var k = 0; k < zeroUsageTopics.length; k++) {
95+
gs.info((k + 1) + '. ' + zeroUsageTopics[k]);
96+
}
97+
} else {
98+
if (topicField) {
99+
gs.info('All active & published topics have been used');
100+
} else {
101+
gs.info('Cannot analyze usage - conversation table not available');
102+
}
103+
}
104+
}
105+
106+
gs.info('\n=== Analysis Complete ===');

0 commit comments

Comments
 (0)