How to Handle Flexible Keywords in Inbound Email Actions for Incident Updates?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi Community,
I have an inbound email action script that updates Incident records based on email content. The script works fine when users send structured keywords like status: On-Hold or comments:.
However, the challenge is that users often use variations like:
- For status: On Hold, on-hold, pending, closed, done
- For comments: Comment, COMMENTS, Additional comments
When these variations occur, the incident does not update because the script checks for exact matches.
What I Want to Achieve:
- Make the script case-insensitive for keywords.
- Allow multiple keyword variations using arrays (e.g., ["on-hold", "on hold", "pending"] for status).
- Keep the existing structure but add array-based checks for flexibility.
Question:
Is this the best approach for handling flexible keywords in inbound email actions?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
HEY @vikasverma1
This issue happens because inbound emails rarely follow exact keywords. Users use different words and cases, so strict comparisons fail.
Best approach
Convert the email body to lowercase once and use keyword arrays for matching. This makes the script case insensitive and flexible without changing the overall structure.
Why this works
It handles real user behavior
Easy to add new keyword variations
Commonly used and maintainable
script
var sysValidEmail = new GlideRecord('sys_properties');
sysValidEmail.addQuery('name', 'ApplicationEmailList');
sysValidEmail.query();
if (sysValidEmail.next()) {
if (current.getTableName() == 'incident' &&
sysValidEmail.value.toLowerCase().includes(email.origemail.toLowerCase())) {
var emailText = email.body_text.toLowerCase();
current.comments_and_work_notes =
'Reply from: ' + email.origemail + '\n\n' + email.body_text;
var onHoldKeywords = ['on hold', 'on-hold', 'pending'];
var inProgressKeywords = ['in progress', 'in-progress', 'working'];
var resolvedKeywords = ['resolved', 'closed', 'done', 'completed'];
if (containsAny(emailText, onHoldKeywords)) {
current.state = 3;
current.hold_reason = 1;
} else if (containsAny(emailText, inProgressKeywords)) {
current.state = 2;
} else if (containsAny(emailText, resolvedKeywords)) {
current.state = 6;
current.close_code = 'Solution provided';
current.close_notes = email.body_text;
}
var commentKeywords = ['comments:', 'comment:', 'additional comments'];
for (var i = 0; i < commentKeywords.length; i++) {
var idx = emailText.indexOf(commentKeywords[i]);
if (idx > -1) {
current.comments =
email.body_text.substring(idx + commentKeywords[i].length);
break;
}
}
GlideSysAttachment.copy(
'sys_email',
sys_email.sys_id,
'incident',
current.sys_id
);
current.update();
} else {
logger.log(
'Update Incident blocked. User ' + email.origemail +
' is not authorized'
);
}
}
function containsAny(text, keywords) {
for (var i = 0; i < keywords.length; i++) {
if (text.indexOf(keywords[i]) > -1) {
return true;
}
}
return false;
}*************************************************************************************************************
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hello @vikasverma1 ,
One approach I get is that you can drive these from System Properties.
Create a system property for every status and values of those status, which are possible.
In the Inbound script, get this system property and check whether the status given in the email is part of the acceptable On-Hold status, or the given status is part of the acceptable Resolved Status etc,.
You can update the system properties of On-Hold, Resolved and the other whenever you get to see the new word without changing the Inbound Email action.
If the above information helps you, Kindly mark it as Helpful and Accept the solution.
Regards,
Najmuddin
