- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-28-2023 03:42 AM
Hi Team ,
We are trying to fetch key values attributes from incoming email template using inbound email actions ,So we can convert into json and proceed with validation and insert the data into case record
But we are getting undefined :
Below is my email template :
Category : test2
Subcategory : test2
Short_description :test
Urgency : 2 - High
Contact : test@test.com
Contact_Work_Phone : 123
Helpdesk_Contact : test1@test.com
Below is my code :Inbound email action
try{
// Check if the email body exists and contains the expected fields
Var emailBody=email.body;
if (emailBody) {
var extractedData = {
'Category': emailBody.Category,
'Subcategory': emailBody.Subcategory,
'Short_description': emailBody.Short_description,
'Urgency': emailBody.Urgency,
'Contact': emailBody.Contact,
'Contact_Work_Phone': emailBody.Contact_Work_Phone,
'Helpdesk_Contact': emailBody.Helpdesk_Contact
};
gs.info("Inbound mail test: " + JSON.stringify(extractedData));
} else {
gs.error("Email body not found or does not contain the expected fields.");
}
}catch (e) {
gs.info('Inbound mail test:error' + e);
}
Please guide me with best practices
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-28-2023 05:06 AM
if the email contains key:value format then simply do this
1) convert everything to lowercase and add _ for spaces
Example below
Contact_Work_Phone -> email.body.contact_work_phone
Helpdesk Contact -> email.body.helpdesk_contact
try this
try{
// Check if the email body exists and contains the expected fields
var emailBody = email.body;
if (emailBody) {
var extractedData = {
'Category': emailBody.category,
'Subcategory': emailBody.subcategory,
'Short_description': emailBody.short_description,
'Urgency': emailBody.urgency,
'Contact': emailBody.contact,
'Contact_Work_Phone': emailBody.contact_work_phone,
'Helpdesk_Contact': emailBody.helpdesk_contact
};
gs.info("Inbound mail test: " + JSON.stringify(extractedData));
} else {
gs.error("Email body not found or does not contain the expected fields.");
}
}catch (e) {
gs.info('Inbound mail test:error' + e);
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-29-2023 08:22 AM
Hi @Ankur Bawiskar got it ,thanks 😀