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

yashkamde
Kilo Sage

Hello @The Matrix ,

 

Try out below code as shown in image. And always send the correct choice label in the mail.

This will help to detect keywords from email and set category and subcat in Incident..

 

yashkamde_0-1770621296324.png

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

if (email.body.category != undefined) {
current.category = getChoiceValue(current.getTableName(), "category", email.body.category.trim());
}
if (email.body.sub_category != undefined) {
current.subcategory = getChoiceValue(current.getTableName(), "subcategory", email.body.sub_category.trim());
}

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

function getChoiceValue(table, field, label) {
var choiceGr = new GlideRecord("sys_choice");
choiceGr.addQuery("name=" + table);
choiceGr.addQuery("element=" + field);
choiceGr.addQuery("label=" + label);
choiceGr.query();

if (choiceGr.next()) {
return choiceGr.value.toString();
}

return label;
}

 

If my response helped mark as helpful and accept the solution.

Dr Atul G- LNG
Tera Patron

Yes @The Matrix 

 

It’s possible, but there’s no direct out-of-the-box way to do it like a drag-and-drop solution. You’ll need to write a script to parse the email body, extract keywords, and then use those keywords to categorize the subject.

Make sure the category and subcategory names match the regex patterns, since the category–subcategory dependency needs to be maintained so the relationship stays intact. You can also use an internal prediction engine to more accurately match keywords with categories and apply them accordingly.

Give it a try and share your feedback.

*************************************************************************************************************
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/dratulgrover [ Connect for 1-1 Session]

****************************************************************************************************************