From 3b5b7497501cd563df4cc238ba114957ae1f9ed4 Mon Sep 17 00:00:00 2001 From: Chase Miller <46936509+ChaseMillers@users.noreply.github.com> Date: Sat, 18 Oct 2025 07:04:59 -0700 Subject: [PATCH 1/2] 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. --- .../script.js | 106 ++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 Server-Side Components/Background Scripts/Virtual Agent Topic Coverage Report/script.js diff --git a/Server-Side Components/Background Scripts/Virtual Agent Topic Coverage Report/script.js b/Server-Side Components/Background Scripts/Virtual Agent Topic Coverage Report/script.js new file mode 100644 index 0000000000..35eb5a96b9 --- /dev/null +++ b/Server-Side Components/Background Scripts/Virtual Agent Topic Coverage Report/script.js @@ -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 ==='); From 8c9d4b71dee1d6b5771e59d3ccbf6483e917f9c2 Mon Sep 17 00:00:00 2001 From: Chase Miller <46936509+ChaseMillers@users.noreply.github.com> Date: Sat, 18 Oct 2025 07:05:23 -0700 Subject: [PATCH 2/2] Add files via upload added readme --- .../README.md | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 Server-Side Components/Background Scripts/Virtual Agent Topic Coverage Report/README.md diff --git a/Server-Side Components/Background Scripts/Virtual Agent Topic Coverage Report/README.md b/Server-Side Components/Background Scripts/Virtual Agent Topic Coverage Report/README.md new file mode 100644 index 0000000000..b81cc30eaa --- /dev/null +++ b/Server-Side Components/Background Scripts/Virtual Agent Topic Coverage Report/README.md @@ -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. \ No newline at end of file