Priority mapping using inbound action

Hafsa1
Mega Sage

Hi 

There is requirement to get priority on csm case using "new" inbound action.

If email body or email subject or email header contains below keyword then priority to be set accordingly.

word like "critical" or "urgent" or "complicated"  then Priority 1

word like "important"  or "sla breach" or "attention" then Priority 2

word like "Low" or "information only" or "optional" then Priority 3

 

 

These words can be added/removed /adjusted in future so need to do using system properties.

Created 3 different system properties. But how to call and match multiple values from property in inbound action

1 ACCEPTED SOLUTION

Tanushree Maiti
Giga Patron

Hi @Hafsa1 

 

Try with this:

Create these sys_properties records.

  • Property Name: csm.priority1.keywords | Value: critical,urgent,complicated
  • Property Name: csm.priority2.keywords | Value: important,sla breach,attention
  • Property Name: csm.priority3.keywords | Value: low,information only,optional

 

  1. Inbound email action script

(function runAction(email, current, event, email_log, logger) {

    var emailContent = (email.subject + " " + email.body_text + " " + email.header).toLowerCase();

    var p1Keywords = gs.getProperty('csm.priority1.keywords').toLowerCase().split(',');

    var p2Keywords = gs.getProperty('csm.priority2.keywords').toLowerCase().split(',');

    var p3Keywords = gs.getProperty('csm.priority3.keywords').toLowerCase().split(',');

 

    if (containsAnyKeyword(emailContent, p1Keywords)) {

        current.priority = 1;

    }

    else if (containsAnyKeyword(emailContent, p2Keywords)) {

        current.priority = 2;

    }

   else if (containsAnyKeyword(emailContent, p3Keywords)) {

        current.priority = 3;

    }

    current.insert();

 

    function containsAnyKeyword(text, keywordArray) {

        for (var i = 0; i < keywordArray.length; i++) {

            var keyword = keywordArray[i].trim();

            if (keyword && text.indexOf(keyword) > -1) {

                return true; // Match found

            }

        }

        return false;

    }

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

 

 

Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin:

View solution in original post

3 REPLIES 3

Dr Atul G- LNG
Tera Patron

https://www.servicenow.com/community/itsm-forum/how-to-call-system-property-in-inbound-action/m-p/24... 

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0535434

 

*************************************************************************************************************
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]

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

Tanushree Maiti
Giga Patron

Hi @Hafsa1 

 

Try with this:

Create these sys_properties records.

  • Property Name: csm.priority1.keywords | Value: critical,urgent,complicated
  • Property Name: csm.priority2.keywords | Value: important,sla breach,attention
  • Property Name: csm.priority3.keywords | Value: low,information only,optional

 

  1. Inbound email action script

(function runAction(email, current, event, email_log, logger) {

    var emailContent = (email.subject + " " + email.body_text + " " + email.header).toLowerCase();

    var p1Keywords = gs.getProperty('csm.priority1.keywords').toLowerCase().split(',');

    var p2Keywords = gs.getProperty('csm.priority2.keywords').toLowerCase().split(',');

    var p3Keywords = gs.getProperty('csm.priority3.keywords').toLowerCase().split(',');

 

    if (containsAnyKeyword(emailContent, p1Keywords)) {

        current.priority = 1;

    }

    else if (containsAnyKeyword(emailContent, p2Keywords)) {

        current.priority = 2;

    }

   else if (containsAnyKeyword(emailContent, p3Keywords)) {

        current.priority = 3;

    }

    current.insert();

 

    function containsAnyKeyword(text, keywordArray) {

        for (var i = 0; i < keywordArray.length; i++) {

            var keyword = keywordArray[i].trim();

            if (keyword && text.indexOf(keyword) > -1) {

                return true; // Match found

            }

        }

        return false;

    }

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

 

 

Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin:

Mark Manders
Giga Patron

Your priority will be relying on a string value that is set by an end user in their email subject.

So "Create a report for marketing (not urgent)" will create a P1 and "Levels are way below acceptable" will create a P3 (yes: 'low' and 'below' are handled the same in a string).


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark