|
| 1 | +# Mock Data Seeder for VA Topic Coverage Report |
| 2 | + |
| 3 | +Use this script to create test data for the Virtual Agent Topic Coverage Report. |
| 4 | + |
| 5 | +## Mock Data Script |
| 6 | + |
| 7 | +Run this in **System Definition → Scripts - Background** to create test topics: |
| 8 | + |
| 9 | +```javascript |
| 10 | +// Generate mock VA topics for testing Topic Coverage Report |
| 11 | +// Creates topics with various states (active/inactive, published/unpublished) |
| 12 | + |
| 13 | +(function() { |
| 14 | + var TEST_TOPICS = [ |
| 15 | + {name: 'Password Reset Help', active: true, published: true, hasConversations: true, count: 15}, |
| 16 | + {name: 'VPN Access Request', active: true, published: true, hasConversations: true, count: 8}, |
| 17 | + {name: 'Laptop Request', active: true, published: true, hasConversations: false, count: 0}, |
| 18 | + {name: 'Printer Support', active: true, published: false, hasConversations: false, count: 0}, |
| 19 | + {name: 'Email Issues', active: false, published: true, hasConversations: false, count: 0}, |
| 20 | + {name: 'Test Topic Draft', active: false, published: false, hasConversations: false, count: 0} |
| 21 | + ]; |
| 22 | + |
| 23 | + var topicGr = new GlideRecord('sys_cs_topic'); |
| 24 | + if (!topicGr.isValid()) { |
| 25 | + gs.error('Table sys_cs_topic not found. Virtual Agent may not be installed.'); |
| 26 | + return; |
| 27 | + } |
| 28 | + |
| 29 | + // Auto-detect conversation field |
| 30 | + var convGr = new GlideRecord('sys_cs_conversation'); |
| 31 | + var topicField = null; |
| 32 | + if (convGr.isValid()) { |
| 33 | + topicField = convGr.isValidField('topic') ? 'topic' : |
| 34 | + (convGr.isValidField('selected_topic') ? 'selected_topic' : null); |
| 35 | + } |
| 36 | + |
| 37 | + gs.info('Creating ' + TEST_TOPICS.length + ' test VA topics...'); |
| 38 | + |
| 39 | + for (var i = 0; i < TEST_TOPICS.length; i++) { |
| 40 | + var topic = TEST_TOPICS[i]; |
| 41 | + |
| 42 | + // Check if topic already exists |
| 43 | + topicGr.initialize(); |
| 44 | + topicGr.addQuery('name', topic.name); |
| 45 | + topicGr.setLimit(1); |
| 46 | + topicGr.query(); |
| 47 | + |
| 48 | + var topicId; |
| 49 | + if (topicGr.next()) { |
| 50 | + topicId = topicGr.getUniqueValue(); |
| 51 | + gs.info('Topic already exists: ' + topic.name); |
| 52 | + } else { |
| 53 | + // Create new topic |
| 54 | + topicGr.initialize(); |
| 55 | + topicGr.setValue('name', topic.name); |
| 56 | + if (topicGr.isValidField('short_description')) { |
| 57 | + topicGr.setValue('short_description', 'Test topic for coverage report'); |
| 58 | + } |
| 59 | + topicGr.setValue('active', topic.active); |
| 60 | + topicGr.setValue('published', topic.published); |
| 61 | + topicId = topicGr.insert(); |
| 62 | + gs.info('Created topic: ' + topic.name + ' (active: ' + topic.active + ', published: ' + topic.published + ')'); |
| 63 | + } |
| 64 | + |
| 65 | + // Create conversations if needed |
| 66 | + if (topic.hasConversations && topicField && topicId) { |
| 67 | + for (var j = 0; j < topic.count; j++) { |
| 68 | + convGr.initialize(); |
| 69 | + convGr.setValue(topicField, topicId); |
| 70 | + if (convGr.isValidField('state')) convGr.setValue('state', 2); // closed |
| 71 | + convGr.insert(); |
| 72 | + } |
| 73 | + gs.info(' Created ' + topic.count + ' conversations for: ' + topic.name); |
| 74 | + } |
| 75 | + } |
| 76 | + |
| 77 | + gs.info('\n=== Mock Data Complete ==='); |
| 78 | + gs.info('Run the Virtual Agent Topic Coverage Report to see results!'); |
| 79 | +})(); |
| 80 | +``` |
| 81 | + |
| 82 | +## Expected Output |
| 83 | + |
| 84 | +After running the mock data seeder, your coverage report should show: |
| 85 | + |
| 86 | +- **Total Topics**: 6 |
| 87 | +- **Inactive Topics**: 2 (Email Issues, Test Topic Draft) |
| 88 | +- **Unpublished Topics**: 2 (Printer Support, Test Topic Draft) |
| 89 | +- **Topics with Zero Usage**: 1 (Laptop Request - active & published but no conversations) |
0 commit comments