Skip to content
Closed
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
31 changes: 31 additions & 0 deletions Client-Side Components/Smart-field-suggestions/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Smart Field Suggestions Based on Keywords

## Category
Client-Side Components / Client Scripts

## Description
This is an onChange Client Script designed for the Incident table that dynamically suggests and populates the Category, Subcategory, and Priority fields based on keywords detected in the Short Description field. By matching keywords, it prompts users to confirm applying suggestions aligned with backend choice values for seamless integration.

## Use Case
During incident creation or update, manually categorizing tickets correctly is critical for IT operations efficiency. This snippet automates early triage by analyzing user-entered short descriptions, providing actionable suggestions to improve categorization accuracy, accelerate routing, and enhance resolution speed.

## How to Use
- Add this script as an "onChange" client script on the Incident table's `short_description` field.
- Ensure the Category, Subcategory, and Priority fields have choice lists aligned with backend values specified in the snippet.
- Modify the keyword list to align with your organizational terminologies if needed.
- The user will be prompted with suggestions and may confirm or dismiss them, allowing balanced automation and human control.

## Why This Use Case is Unique and Valuable

- Dynamically assists in categorizing incidents early, improving routing and resolution time.
- Uses only platform APIs (`g_form`) without custom backend code or external integrations, making it lightweight and maintainable.
- Uses real backend choice values ensuring seamless compatibility with existing configurations, reducing errors.
- Provides prompt suggestions with user confirmation, balancing automation and user control.
- Easily adaptable for other fields, keywords, or use cases beyond Incident management.
- Designed without fragile DOM manipulations, following ServiceNow best practices, tailored for real environments.

## Compatibility
This client script is compatible with all ServiceNow instances .

## Files
- `Script.js` — the client script implementing the logic.
73 changes: 73 additions & 0 deletions Client-Side Components/Smart-field-suggestions/Script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || !newValue || newValue.length < 10) {
return;
}

var keywords = [
{
pattern: /password|login|access/i,
category: 'inquiry | Help ',
subcategory: 'antivirus',
priority: '3',
suggestion: 'This appears to be a Inquiry issue.'
},
{
pattern: /slow|performance|hanging/i,
category: 'software',
subcategory: 'email',
priority: '2',
suggestion: 'This appears to be a Software issue.'
},
{
pattern: /printer|print|printing/i,
category: 'hardware',
subcategory: 'monitor',
priority: '3',
suggestion: 'This appears to be a Hardware issue.'
},
{
pattern: /database|data/i,
category: 'database',
subcategory: 'db2',
priority: '3',
suggestion: 'This appears to be an Database issue.'
},
{
pattern: /network|internet|wifi|connection/i,
category: 'network',
subcategory: 'vpn',
priority: '2',
suggestion: 'This appears to be a network issue.'
}

];

var lowerDesc = newValue.toLowerCase();
var matched = null;

for (var i = 0; i < keywords.length; i++) {
if (keywords[i].pattern.test(lowerDesc)) {
matched = keywords[i];
break;
}
}

g_form.hideFieldMsg('short_description', true);
g_form.clearMessages();

if (matched) {
g_form.showFieldMsg('short_description', matched.suggestion, 'info', false);

if (confirm(matched.suggestion + "\n\nApply these suggestions?")) {
g_form.setValue('category', matched.category);
g_form.setValue('subcategory', matched.subcategory); // Make sure you use backend value for subcategory!
g_form.setValue('priority', matched.priority);
g_form.addInfoMessage('Suggestions applied automatically!');
} else {
g_form.addInfoMessage('Suggestions dismissed.');
g_form.hideFieldMsg('short_description', true);
}
} else {
g_form.addInfoMessage('No keywords matched in description.');
}
}
Loading