Skip to content
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//Scenario: whenever a user submits a ticket (Incident, HR Case, etc.), the system analyzes the tone of the message - like frustrated, urgent, calm, confused
// and automatically adjusts the ticket priority, or routes it to a specific team (like “Empathy Response Desk)

var EmotionAnalyzer = Class.create();
EmotionAnalyzer.prototype = {
initialize: function() {},

detectEmotion: function(text) {
try {
// ---- Mock Sentiment Logic (No external API) ----
text = text.toLowerCase();
var score = 0;
var negativeWords = ['angry', 'frustrated', 'bad', 'urgent', 'hate', 'delay'];
var positiveWords = ['thank', 'happy', 'great', 'awesome', 'love'];

negativeWords.forEach(function(word) {
if (text.includes(word)) score -= 1;
});
positiveWords.forEach(function(word) {
if (text.includes(word)) score += 1;
});

var sentiment = (score > 0) ? 'positive' : (score < 0) ? 'negative' : 'neutral';
return { sentiment: sentiment, score: Math.abs(score / 3) };
} catch (e) {
gs.error("EmotionAnalyzer error: " + e.message);
return { sentiment: 'neutral', score: 0 };
}
},

type: 'EmotionAnalyzer'
};
29 changes: 29 additions & 0 deletions Server-Side Components/Script Includes/Emotion-Aware/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
### Overview
The **Emotion-Aware Ticket Prioritizer** is an AI-driven innovation for ServiceNow that automatically analyzes the tone and emotion of user-submitted tickets (Incidents, HR Cases, etc.) to determine the urgency and emotional state of the user.
If frustration or urgency is detected, the system dynamically increases the **priority**, adds contextual **work notes**, and routes the ticket to the right team — ensuring faster resolution and better user experience.

---

## How It Works
1. When a ticket is created, a **Business Rule** triggers a **Script Include** (`EmotionAnalyzer`).
2. The Script Include analyzes the short description and description text.
3. It detects emotional tone — *positive*, *neutral*, or *negative*.
4. Based on sentiment, the system:
- Adjusts **priority** automatically
- Adds a **work note** with detected emotion
- Optionally, notifies the support team for urgent or frustrated cases

---
## How It Trigger Script Include Via Business Rule
1. Create object of Script Include (Accessible from all scopes)
var util = new global.EmotionAnalyzer();

----
## Example line as input and output
| User Input | Detected Emotion | Auto Priority | Output |
| -------------------------------------- | ---------------- | ------------- | --------------------- |
| “Laptop crashed again, no one helps!” | Negative | 1 (Critical) | Escalate to VIP queue |
| “Thank you, system working great now!” | Positive | 4 (Low) | No action |
| “Need help resetting my password.” | Neutral | 3 (Moderate) | Normal SLA |


Loading