Skip to content

Commit 8ccf794

Browse files
authored
Smart Field Suggestions Based on Keyword (#2029)
* Created Smart Field Suggestions * deleting the file to move file to a folder * Moved Incident-smart-field-suggestion file to Smart-field-sugeestion folder . * Create README.md * Deleting the README.md it is not in right path * Delete Client-Side Components/Smart-field-suggestions/Script.js as it is placed in wrong path * Created Smart Field Suggestions Based on Keyword.js in Correct Path * Created README.md file in correct path
1 parent d890f1b commit 8ccf794

File tree

2 files changed

+106
-0
lines changed

2 files changed

+106
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Smart Field Suggestions Based on Keywords
2+
3+
## Category
4+
Client-Side Components / Client Scripts
5+
6+
## Description
7+
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.
8+
9+
## Use Case
10+
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.
11+
12+
## How to Use
13+
- Add this script as an "onChange" client script on the Incident table's `short_description` field.
14+
- Ensure the Category, Subcategory, and Priority fields have choice lists aligned with backend values specified in the snippet.
15+
- Modify the keyword list to align with your organizational terminologies if needed.
16+
- The user will be prompted with suggestions and may confirm or dismiss them, allowing balanced automation and human control.
17+
18+
## Why This Use Case is Unique and Valuable
19+
20+
- Dynamically assists in categorizing incidents early, improving routing and resolution time.
21+
- Uses only platform APIs (`g_form`) without custom backend code or external integrations, making it lightweight and maintainable.
22+
- Uses real backend choice values ensuring seamless compatibility with existing configurations, reducing errors.
23+
- Provides prompt suggestions with user confirmation, balancing automation and user control.
24+
- Easily adaptable for other fields, keywords, or use cases beyond Incident management.
25+
- Designed without fragile DOM manipulations, following ServiceNow best practices, tailored for real environments.
26+
27+
## Compatibility
28+
This client script is compatible with all standard ServiceNow instances without requiring ES2021 features.
29+
30+
## Files
31+
- `Smart Field Suggestions Based on Keyword.js` — the client script implementing the logic.
32+
33+
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
2+
if (isLoading || !newValue || newValue.length < 10) {
3+
return;
4+
}
5+
6+
var keywords = [
7+
{
8+
pattern: /password|login|access/i,
9+
category: 'inquiry | Help ',
10+
subcategory: 'antivirus',
11+
priority: '3',
12+
suggestion: 'This appears to be a Inquiry issue.'
13+
},
14+
{
15+
pattern: /slow|performance|hanging/i,
16+
category: 'software',
17+
subcategory: 'email',
18+
priority: '2',
19+
suggestion: 'This appears to be a Software issue.'
20+
},
21+
{
22+
pattern: /printer|print|printing/i,
23+
category: 'hardware',
24+
subcategory: 'monitor',
25+
priority: '3',
26+
suggestion: 'This appears to be a Hardware issue.'
27+
},
28+
{
29+
pattern: /database|data/i,
30+
category: 'database',
31+
subcategory: 'db2',
32+
priority: '3',
33+
suggestion: 'This appears to be an Database issue.'
34+
},
35+
{
36+
pattern: /network|internet|wifi|connection/i,
37+
category: 'network',
38+
subcategory: 'vpn',
39+
priority: '2',
40+
suggestion: 'This appears to be a network issue.'
41+
}
42+
43+
];
44+
45+
var lowerDesc = newValue.toLowerCase();
46+
var matched = null;
47+
48+
for (var i = 0; i < keywords.length; i++) {
49+
if (keywords[i].pattern.test(lowerDesc)) {
50+
matched = keywords[i];
51+
break;
52+
}
53+
}
54+
55+
g_form.hideFieldMsg('short_description', true);
56+
g_form.clearMessages();
57+
58+
if (matched) {
59+
g_form.showFieldMsg('short_description', matched.suggestion, 'info', false);
60+
61+
if (confirm(matched.suggestion + "\n\nApply these suggestions?")) {
62+
g_form.setValue('category', matched.category);
63+
g_form.setValue('subcategory', matched.subcategory); // Make sure you use backend value for subcategory!
64+
g_form.setValue('priority', matched.priority);
65+
g_form.addInfoMessage('Suggestions applied automatically!');
66+
} else {
67+
g_form.addInfoMessage('Suggestions dismissed.');
68+
g_form.hideFieldMsg('short_description', true);
69+
}
70+
} else {
71+
g_form.addInfoMessage('No keywords matched in description.');
72+
}
73+
}

0 commit comments

Comments
 (0)