Phase 1 adds the database foundation for search, filtering, and tagging features:
- AI Provider field (7 provider options)
- Many-to-many category table (multiple categories per prompt)
- Migration script for existing data
- ServiceNow instance access with admin privileges
- ServiceNow Studio access
- Access to the ServiceNow GenAI Prompt Library application scope
If you're using ServiceNow Source Control integration:
- Navigate to Studio in your ServiceNow instance
- Open the ServiceNow GenAI Prompt Library application
- Click Source Control > Pull from Repository
- This will import all the new XML files automatically
OR If manually importing:
- Download the following files from the repository
- Import them via System Update Sets or Studio
- Navigate to System Definition > Tables
- Search for table:
x_snc_ehd_servic_0_prompt - Open the table and go to Columns tab
- Verify field
ai_providerexists (String, max_length: 40)
- Navigate to System Definition > Choice Lists
- Search for table:
x_snc_ehd_servic_0_prompt, element:ai_provider - Verify 7 choices exist:
- ✅ claude → "Claude (Anthropic)"
- ✅ github_copilot → "GitHub Copilot"
- ✅ ms_copilot → "Microsoft Copilot"
- ✅ chatgpt → "ChatGPT (OpenAI)"
- ✅ gemini → "Gemini (Google)"
- ✅ now_assist → "Now Assist (ServiceNow)"
- ✅ other → "Other AI Provider"
- Navigate to System Definition > Tables
- Search for:
x_snc_ehd_servic_0_prompt_category_m2m - Verify table exists with fields:
prompt(Reference to x_snc_ehd_servic_0_prompt)category(Reference to x_snc_ehd_servic_0_category)
This script migrates existing single-category relationships to the new many-to-many table.
- Navigate to System Definition > Scripts - Background
- Run this script to check current state:
// Check migration status BEFORE running migration
var migrator = new x_snc_ehd_servic_0.MigratePromptCategories();
var status = migrator.checkStatus();
gs.info('=== MIGRATION STATUS (BEFORE) ===');
gs.info('Total Active Prompts: ' + status.totalPrompts);
gs.info('Prompts with Category: ' + status.promptsWithCategory);
gs.info('M2M Records: ' + status.m2mRecords);
gs.info('Prompts Needing Migration: ' + status.promptsNotInM2M.length);
if (status.promptsNotInM2M.length > 0) {
gs.info('Sample prompts needing migration: ' + status.promptsNotInM2M.slice(0, 10).join(', '));
}Expected Output:
- Should show your total prompts and how many have categories
- M2M Records should be 0 (or very low if some already exist)
- You should see prompts that need migration
Once you've verified the status, run the migration:
// Run the migration
var migrator = new x_snc_ehd_servic_0.MigratePromptCategories();
var results = migrator.migrate();
gs.info('=== MIGRATION RESULTS ===');
gs.info('Total Prompts Processed: ' + results.totalPrompts);
gs.info('Successfully Migrated: ' + results.migratedPrompts);
gs.info('Prompts Without Category: ' + results.promptsWithoutCategory);
gs.info('Duplicates Skipped: ' + results.duplicatesSkipped);
if (results.errors.length > 0) {
gs.error('Errors occurred: ' + results.errors.length);
results.errors.forEach(function(err) {
gs.error(' - ' + err);
});
} else {
gs.info('Migration completed successfully with no errors!');
}Expected Output:
- Successfully Migrated should equal Prompts with Category
- Errors should be empty
- You'll see progress messages every 100 prompts
Run the status check again to verify migration completed:
// Verify migration completed successfully
var migrator = new x_snc_ehd_servic_0.MigratePromptCategories();
var status = migrator.checkStatus();
gs.info('=== MIGRATION STATUS (AFTER) ===');
gs.info('Total Active Prompts: ' + status.totalPrompts);
gs.info('Prompts with Category: ' + status.promptsWithCategory);
gs.info('M2M Records: ' + status.m2mRecords);
gs.info('Prompts Still Needing Migration: ' + status.promptsNotInM2M.length);
// Validation
if (status.m2mRecords === status.promptsWithCategory) {
gs.info('✅ SUCCESS: All prompts with categories have been migrated!');
} else {
gs.warn('⚠️ WARNING: M2M record count does not match prompts with categories');
gs.warn('This could be normal if some prompts have multiple categories already');
}
if (status.promptsNotInM2M.length === 0) {
gs.info('✅ SUCCESS: No prompts remaining to migrate!');
} else {
gs.warn('⚠️ WARNING: ' + status.promptsNotInM2M.length + ' prompts still need migration');
gs.warn('Sample: ' + status.promptsNotInM2M.slice(0, 10).join(', '));
}- Navigate to ServiceNow GenAI Prompt Library > Prompts
- Open any prompt record
- Scroll to find the AI Provider field
- Verify the dropdown shows all 7 provider options
- Select a provider and save
- Verify it saves correctly
- Navigate to System Definition > Tables & Columns
- Search for and open:
x_snc_ehd_servic_0_prompt_category_m2m - Click Show records in this table
- Verify you see records with prompt and category references
- Pick a few random records and verify:
- Prompt reference is valid
- Category reference is valid
- They match the original prompt's category
- Navigate to ServiceNow GenAI Prompt Library > Prompts
- Open 3-5 random prompts
- For each prompt:
- Note the category in the
categoryfield - Navigate to the Related Lists at the bottom
- Look for Prompt Category M2M related list
- Verify the related list shows a matching category entry
- Note the category in the
For better performance, add indexes on the new fields:
// Note: This may require elevated permissions
// You may need to work with your ServiceNow admin to create these indexes
// Create index on ai_provider field
// Navigate to: System Definition > Tables
// Open x_snc_ehd_servic_0_prompt
// Go to Database Indexes tab
// Create new index on 'ai_provider' column
// Create index on m2m prompt field
// Navigate to: System Definition > Tables
// Open x_snc_ehd_servic_0_prompt_category_m2m
// Go to Database Indexes tab
// Create new index on 'prompt' column
// Create index on m2m category field
// Create another index on 'category' columnOR via background script (if you have permissions):
// WARNING: Only run if you have database admin permissions
// This creates indexes for better query performance
var indexHelper = new GlideDBObjectManager();
// Index on prompt table - ai_provider field
gs.info('Creating index on x_snc_ehd_servic_0_prompt.ai_provider...');
// Note: Actual index creation requires admin privileges
// Consult your DBA or use ServiceNow UI method above
gs.info('Phase 1 database indexes should be created via ServiceNow UI');
gs.info('See deployment guide for instructions');After deployment, verify:
- AI Provider field appears on prompt records
- All 7 provider choices are available in the dropdown
- M2M table created successfully (x_snc_ehd_servic_0_prompt_category_m2m)
- Migration script executed without errors
- M2M record count matches prompts with categories
- Spot check: 3-5 random prompts have correct m2m entries
- Can manually select AI provider on a prompt and save
- No errors in system logs related to new schema
- (Optional) Database indexes created for performance
If issues occur, you can rollback:
- Navigate to System Update Sets > Retrieved Update Sets
- Find the update set containing Phase 1 changes
- Select Back out this update set
- This will remove the new fields and table
-
Delete m2m table:
- Navigate to System Definition > Tables
- Find
x_snc_ehd_servic_0_prompt_category_m2m - Delete the table (this also deletes all m2m records)
-
Remove AI Provider field:
- Navigate to System Definition > Tables
- Open
x_snc_ehd_servic_0_prompt - Find
ai_providerfield in Columns tab - Delete the field
-
Remove choices:
- Navigate to System Definition > Choice Lists
- Search for
ai_providerchoices - Delete all 7 choice records
-
Remove migration script:
- Navigate to System Definition > Script Includes
- Find
MigratePromptCategories - Delete the script include
Note: Rollback is safe because:
- No existing data is modified (category field remains unchanged)
- M2M table is new and doesn't affect existing functionality
- AI Provider field is optional (empty values are allowed)
Error: x_snc_ehd_servic_0.MigratePromptCategories is not defined
Solution:
- Verify the script include was imported
- Navigate to System Definition > Script Includes
- Search for:
MigratePromptCategories - Verify it's in the correct scope:
x_snc_ehd_servic_0
Error: Table x_snc_ehd_servic_0_prompt_category_m2m is invalid
Solution:
- Check if table was created in correct scope
- Navigate to System Definition > Tables
- Search for:
x_snc_ehd_servic_0_prompt_category_m2m - If missing, re-import the table XML file
Symptom: Migration reports duplicates skipped
Solution:
- This is normal if you run migration multiple times
- The script checks for existing records and skips them
- No action needed
Symptom: promptsNotInM2M.length > 0 after migration
Solution:
- Check if those prompts have null category (expected)
- Verify prompts are active
- Re-run migration script (safe to run multiple times)
Once Phase 1 is deployed, tested, and verified:
- Communicate to users: New AI Provider field is available (optional)
- Monitor for issues: Check system logs for any errors
- Proceed to Phase 2: Basic Search Functionality
- Search box in library widget
- Keyword search implementation
- Clear filters functionality
If you encounter issues:
- Check ServiceNow system logs: System Logs > System Log > All
- Review error messages from migration script
- Verify source control sync completed successfully
- Check that all XML files were imported
Phase 1 adds the database foundation with:
- ✅ AI Provider field with 7 provider choices
- ✅ Many-to-many category table for multiple categories
- ✅ Migration script to populate m2m table
- ✅ Backwards compatibility maintained
- ✅ No breaking changes to existing functionality