From b5fbaa36dfbe9426ebf53b98e07b693cea392e65 Mon Sep 17 00:00:00 2001 From: Yelugu Sriharsha <89392618+Sriharsha19@users.noreply.github.com> Date: Sat, 11 Oct 2025 17:14:52 +0530 Subject: [PATCH 1/4] Created Smart Field Suggestions --- .../Client Scripts/Smart Field Suggestions | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 Client-Side Components/Client Scripts/Smart Field Suggestions diff --git a/Client-Side Components/Client Scripts/Smart Field Suggestions b/Client-Side Components/Client Scripts/Smart Field Suggestions new file mode 100644 index 0000000000..b3af251bbc --- /dev/null +++ b/Client-Side Components/Client Scripts/Smart Field Suggestions @@ -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.'); + } +} From 5c02e40abaf42ef44ffb0de3e539d492e9f096fb Mon Sep 17 00:00:00 2001 From: Yelugu Sriharsha <89392618+Sriharsha19@users.noreply.github.com> Date: Sat, 11 Oct 2025 17:17:37 +0530 Subject: [PATCH 2/4] deleting the file to move file to a folder --- .../Client Scripts/Smart Field Suggestions | 73 ------------------- 1 file changed, 73 deletions(-) delete mode 100644 Client-Side Components/Client Scripts/Smart Field Suggestions diff --git a/Client-Side Components/Client Scripts/Smart Field Suggestions b/Client-Side Components/Client Scripts/Smart Field Suggestions deleted file mode 100644 index b3af251bbc..0000000000 --- a/Client-Side Components/Client Scripts/Smart Field Suggestions +++ /dev/null @@ -1,73 +0,0 @@ -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.'); - } -} From c7ab30529035c3a52947a1144e1fa9a4ccbd2f58 Mon Sep 17 00:00:00 2001 From: Yelugu Sriharsha <89392618+Sriharsha19@users.noreply.github.com> Date: Sat, 11 Oct 2025 17:28:43 +0530 Subject: [PATCH 3/4] Moved Incident-smart-field-suggestion file to Smart-field-sugeestion folder . --- .../Smart-field-suggestions/Script.js | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 Client-Side Components/Smart-field-suggestions/Script.js diff --git a/Client-Side Components/Smart-field-suggestions/Script.js b/Client-Side Components/Smart-field-suggestions/Script.js new file mode 100644 index 0000000000..b3af251bbc --- /dev/null +++ b/Client-Side Components/Smart-field-suggestions/Script.js @@ -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.'); + } +} From a395d9934e96d85063b11ba34170ab7d9977cdbd Mon Sep 17 00:00:00 2001 From: Yelugu Sriharsha <89392618+Sriharsha19@users.noreply.github.com> Date: Sat, 11 Oct 2025 17:37:57 +0530 Subject: [PATCH 4/4] Create README.md --- .../Smart-field-suggestions/README.md | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Client-Side Components/Smart-field-suggestions/README.md diff --git a/Client-Side Components/Smart-field-suggestions/README.md b/Client-Side Components/Smart-field-suggestions/README.md new file mode 100644 index 0000000000..d1ad144959 --- /dev/null +++ b/Client-Side Components/Smart-field-suggestions/README.md @@ -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.