Help on Inbound email action to read the email body and populate company name on Incident
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-21-2022 12:55 PM - edited ‎12-21-2022 12:58 PM
Hi all,
I have inbound email action working for insert/update by reading the text on the subject of the email. I am currently capturing the company name as I have hardcoded the company sys id in the email script.
Now, I have another requirement where by multiple clients are using the same source email to send the emails to snow system. The company name can be read from the body of the email as below from the "managed by" field:
Devicename: Test Device
Host: Test Host
Location---
City---
Post code---
managed by----a_test_company1 , a_test_company2 , a_test_company3
Can any one guide me on how to achieve this please?
Current script as below: ( not added any thing related to the above requirement)
while (grEmail.next()) {
if(incUpdated == false) {
grInc.get(grEmail.instance);
if (grInc.active == true) {
incUpdated = true;
grInc.work_notes = '\nFrom: ' + email.from + '\nTo: ' + email.to + '\nSubject: ' + email.subject + '\n\n' + email.body_text;
sys_email.target_table = "incident";
sys_email.instance = grInc.sys_id;
sys_email.update();
grInc.update();
}
}
}
if (incUpdated == false) {
// If existing incident not found create new incident
current.caller_id = gs.getUserID();
current.description = "received from: " + email.origemail + "\n\n" + email.body_text;
current.short_description = email.subject;
current.company = 'testcompany';
current.work_notes = "received from: " + email.origemail + "\n\n" + email.body_text;
current.impact = 3;
current.urgency =3;
current.assignment_group = "test";
current.type = "Request";
current.incident_state = IncidentState.NEW;
current.notify = 2;
current.contact_type = "email";
if (email.body.assign != undefined)
current.assigned_to = email.body.assign;
if (email.importance != undefined) {
if (email.importance.toLowerCase() == "low") {
current.impact = 3;
current.urgency = 3;
}
}
current.insert();
}
Any help on this is greatly appreciated. Many thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-21-2022 01:00 PM
Try below script instead of current.company = 'testcompany';
current.company.setDisplayValue(email.body.managed_by.replace('a_test_',''));
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-22-2022 05:16 AM
Thanks very much Sanjiv. I tried this but company is empty.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-22-2022 09:40 AM
Could you please share your updated script?
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-22-2022 01:19 PM
Hi,
Copied the one you sent.
//current.company = 'testcompany';
current.company.setDisplayValue(email.body.managed_by.replace('a_test_',''));
current.work_notes = "received from: " + email.origemail + "\n\n" + email.body_text;
Email body sent as below:
Devicename: Test Device
Host: Test Host
Location---
City---
Post code---
managed by----a_test_ACME Africa