We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

How to detect keywords from email and set category and subcat in inbound email action in Incident?

The Matrix
Tera Contributor

Hi All,

I am working on a POC and need some guidance.

Is it possible to detect specific keywords in the email body and automatically set the Category and Subcategory of an Incident through an inbound email action? What would be the best approach to achieve this?

6 REPLIES 6

pavani_paluri
Tera Guru

Hi @The Matrix ,

 

We can achieve this usning Inbound action. You can refere Solved: I want to set the category to the incident form fr... - ServiceNow Community

 

Also see below code for reference:

 

if (email.body_text.includes("database error")) {
current.category = "Applications";
current.subcategory = "Database";
}
else if (email.body_text.includes("network issue")) {
current.category = "Infrastructure";
current.subcategory = "Network";
}

 

Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Pavani P

Ankur Bawiskar
Tera Patron

@The Matrix 

yes why not

You can use RegEx or indexOf() to search that particular keyword and then set your category and subcategory

where are you stuck?

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

vaishali231
Tera Guru

hey @The Matrix 

Approach

Read the email subject and body.

Convert the content to lowercase to make keyword detection case-insensitive.

Check for specific keywords.

Set category and subcategory before the record is inserted.

This works well for a POC and keeps the logic simple.

Sample Inbound Email Action Script

(function runAction(/*GlideRecord*/ current,
/*GlideRecord*/ event,
/*EmailWrapper*/ email,
/*ScopedEmailLogger*/ logger,
/*EmailClassifier*/ classifier) {

// Combine subject and body for better matching
var body = (email.body_text || "").toLowerCase();
var subject = (email.subject || "").toLowerCase();
var content = body + " " + subject;

// Keyword-based categorization
if (content.indexOf("vpn") > -1) {
current.category = "network";
current.subcategory = "vpn";
}
else if (content.indexOf("outlook") > -1 || content.indexOf("email issue") > -1) {
current.category = "software";
current.subcategory = "email";
}
else if (content.indexOf("laptop") > -1) {
current.category = "hardware";
current.subcategory = "laptop";
}

})(current, event, email, logger, classifier);

*************************************************************************************************************
If this response helps, please mark it as Accept as Solution and Helpful.
Doing so helps others in the community and encourages me to keep contributing.

Regards
Vaishali Singh

hey @The Matrix 

Hope you are doing well.

Did my previous reply answer your question?

If it was helpful, please mark it as correct ✓ and close the thread 🔒. This will help other readers find the solution more easily.

Regards,
Vaishali Singh