Commit 87c4f9e
authored
Incident Sentiment Detector (No AI, Pure JavaScript) (#2259)
* Create readme.md
Incident Sentiment Detector (No AI, Pure JavaScript)
A lightweight ServiceNow utility that detects sentiment (Positive / Negative / Neutral) of an Incident’s short description or comments using simple keyword matching — no AI APIs or external libraries required.
Useful for support teams to auto-tag sentiment and analyze user frustration or satisfaction trends without expensive integrations.
🚀 Features
✅ Detects sentiment directly inside ServiceNow ✅ Works without external APIs or ML models ✅ Instant classification on form update ✅ Adds detected sentiment to a custom field (u_sentiment) ✅ Simple to extend — just add more positive/negative keywords
🧩 Architecture Overview
The solution consists of two main scripts:
Component Type Purpose SentimentAnalyzer Script Include Processes text and returns sentiment Client Script (onChange) Client Script Calls SentimentAnalyzer via GlideAjax on short description change 🧱 Setup Instructions 1️⃣ Create Custom Field
Create a new field on the Incident table:
Name: u_sentiment
Type: Choice
Choices: Positive, Neutral, Negative
* Create SentimentAnalyzer.js
var SentimentAnalyzer = Class.create();
SentimentAnalyzer.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getSentiment: function() {
var text = (this.getParameter('sysparm_text') || '').toLowerCase();
var positive = ['thanks', 'great', 'resolved', 'appreciate'];
var negative = ['issue', 'error', 'not working', 'fail', 'problem'];
var score = 0;
positive.forEach(function(word) { if (text.includes(word)) score++; });
negative.forEach(function(word) { if (text.includes(word)) score--; });
if (score > 0) return 'Positive';
if (score < 0) return 'Negative';
return 'Neutral';
}
});
* Create onChangeClientscript.js1 parent c990397 commit 87c4f9e
File tree
3 files changed
+50
-0
lines changed- Client-Side Components/Catalog Client Script/Incident Sentiment Detector (Using Simple Word Matching, No AI)
3 files changed
+50
-0
lines changedLines changed: 16 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
Lines changed: 11 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
Lines changed: 23 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
0 commit comments