Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Virtual Agent Topic Coverage Report

A background script that analyzes Virtual Agent topic configuration health by identifying inactive, unpublished, or unused topics.

## Usage

1. Navigate to **System Definition → Scripts - Background**
2. Copy and paste the script content
3. (Optional) Modify `daysBack` variable to set the usage analysis timeframe (default: 30 days)
4. Click "Run script"

## What It Does

The script:
1. Queries all Virtual Agent topics in the system
2. Checks each topic's active and published status
3. Counts conversations per topic over the past 30 days (configurable)
4. Displays inactive topics, unpublished topics, and zero-usage topics
5. Helps identify topics that need attention before go-live or during health checks

## Report Categories

**Inactive Topics**: Topics where the "Active" checkbox is unchecked. These topics are disabled and won't respond to user inputs even if published.

**Unpublished Topics**: Topics where the "Published" checkbox is unchecked. These are draft topics not yet available to end users.

**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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,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 ===');
Loading