- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2023 10:34 PM
When I send the below data via email to ServiceNow,
Category: Apps - Data to Report |
Sub Category: Master Data |
It is not taking the Category and Sub category.
If I give the value of the choices in an email like below, it is setting the category and sub category.
Category: Apps - data |
Sub Category: master |
How to write a script to take the label from email and check the label in the choice list and then set it to incident category
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2023 10:54 PM
@Neethi2 Try out below code as shown in image. And always send the correct choice label in the mail.
(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;
}
Please mark as correct answer if this solves your issue.
ServiceNow Community Rising Star, Class of 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2023 10:39 PM
@Neethi2 Have you created inbound action?
ServiceNow Community Rising Star, Class of 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2023 10:42 PM
Yes
Here is the script,
if (email.body.category != undefined) {
current.category= email.body.category;
}
if (email.body.sub_category != undefined) {
current.subcategory= email.body.sub_category;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2023 10:54 PM
@Neethi2 Try out below code as shown in image. And always send the correct choice label in the mail.
(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;
}
Please mark as correct answer if this solves your issue.
ServiceNow Community Rising Star, Class of 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2023 11:38 PM
Thanks a lot.It worked