Help on Inbound email action to read the email body and populate company name on Incident

st27
Tera Contributor

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

 

 

 

 

 

5 REPLIES 5

SanjivMeher
Kilo Patron
Kilo Patron

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.

Thanks very much Sanjiv. I tried this but company is empty.

Could you please share your updated script?


Please mark this response as correct or helpful if it assisted you with your question.

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