Skip to content

Commit 45f2aec

Browse files
authored
added agent topic scanner (#2233)
1 parent d6bba1c commit 45f2aec

File tree

2 files changed

+84
-0
lines changed
  • Server-Side Components/Background Scripts/Virtual Agent Conversation Analytics

2 files changed

+84
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Virtual Agent Conversation Analytics
2+
3+
A background script that analyzes Virtual Agent conversation logs to identify the most common topics over a configurable time period.
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 analysis timeframe (default: 7 days)
10+
4. Click "Run script"
11+
12+
## What It Does
13+
14+
The script:
15+
1. Queries Virtual Agent conversation logs from the past 7 days (configurable)
16+
2. Counts conversations by topic
17+
3. Displays the top 10 most common topics with conversation counts
18+
4. Helps identify which Virtual Agent topics are most frequently used
19+
20+
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Virtual Agent Conversation Analytics
2+
// Analyzes VA conversation logs to identify the most common topics
3+
4+
var daysBack = 7; // Analyze conversations from the past 7 days
5+
6+
// Calculate date range
7+
var startDate = new GlideDateTime();
8+
startDate.addDaysLocalTime(-daysBack);
9+
10+
gs.info('=== Virtual Agent Conversation Analytics ===');
11+
gs.info('Analyzing conversations from: ' + startDate.getDisplayValue());
12+
13+
// Get conversation logs
14+
var convGr = new GlideRecord('sys_cs_conversation');
15+
convGr.addQuery('sys_created_on', '>=', startDate);
16+
convGr.query();
17+
18+
var totalConversations = convGr.getRowCount();
19+
gs.info('Total Conversations: ' + totalConversations);
20+
21+
// Auto-detect topic field (handles schema variations)
22+
var topicField = convGr.isValidField('topic') ? 'topic' :
23+
(convGr.isValidField('selected_topic') ? 'selected_topic' : null);
24+
25+
if (!topicField) {
26+
gs.warn('No topic field found on sys_cs_conversation table');
27+
} else {
28+
// Track topic counts
29+
var topicCounts = {};
30+
31+
while (convGr.next()) {
32+
var topicId = convGr.getValue(topicField);
33+
34+
if (topicId) {
35+
var topicGr = new GlideRecord('sys_cs_topic');
36+
if (topicGr.get(topicId)) {
37+
var topicName = topicGr.getValue('name');
38+
39+
if (!topicCounts[topicName]) {
40+
topicCounts[topicName] = 0;
41+
}
42+
topicCounts[topicName]++;
43+
}
44+
}
45+
}
46+
47+
// Sort and display most common topics
48+
gs.info('\n=== Most Common Topics ===');
49+
var sortedTopics = [];
50+
for (var topic in topicCounts) {
51+
sortedTopics.push({name: topic, count: topicCounts[topic]});
52+
}
53+
sortedTopics.sort(function(a, b) { return b.count - a.count; });
54+
55+
if (sortedTopics.length === 0) {
56+
gs.info('No topics found in the selected time range');
57+
} else {
58+
for (var i = 0; i < Math.min(10, sortedTopics.length); i++) {
59+
gs.info((i + 1) + '. ' + sortedTopics[i].name + ': ' + sortedTopics[i].count + ' conversations');
60+
}
61+
}
62+
}
63+
64+
gs.info('\n=== Analysis Complete ===');

0 commit comments

Comments
 (0)