How do you parse the body of an email?

bobheelan
Giga Contributor

We are getting ready to move to ServiceNow and I have a need to parse existing template emails that were creating tickets in Remedy until we can implement integration with the older system.

The email body contains information formatted in the following manner:

Schema: HPD:IncidentInterface_Create

Server: sscvpremapp.ryder.com

Login: jobabends

Password: ryder123

Action: Submit

Format: Short

z1D_Act!1000000076!:CREATE

LName  !1000000018!:Abends

FName  !1000000019!:Job

S_Type !1000000099!:User Service Restoration

Status !7         !:New

Impact !1000000163!:3-Moderate/Limited

Urgency!1000000162!:3-Medium

Desc   !1000000000!:Job SM730JGD failed. MAXCC=S04C  02/10/19 13_27_45 from CA7

Source !1000000215!:Web

Reason !1000000150!:

Details:Job SM730JGD failed. MAXCC=S04C  02/10/19 13_27_45 from CA7 

I am trying to parse the 'Desc   !1000000000!:" line to use as the short_summary in the incident.

Here is how I am trying to accomplish the task:

var subjectforabend = email.body_text.substr(email.body_text.indexOF("Desc !1000000000!:")+19,email.body_text.indexOF("Desc !1000000000!:")+79);

current.short_description = subjectforabend;

current.caller_id = gs.getUserID();

current.comments = "received from: " + email.origemail + "\n\n" + email.body_text;

current.assignment_group = "74631186db56e3807137ab8b4b9619d5";

//current.category = "inquiry";
current.incident_state = IncidentState.NEW;

current.contact_type = "email";

current.insert();

The ticket is being created but the short summary is blank.

Any assistance will be greatly appreciated.

1 ACCEPTED SOLUTION

Allen Andreas
Administrator
Administrator

Initial issue I see is formatting:

var subjectforabend = email.body_text.substr(email.body_text.indexOF("Desc !1000000000!:")+19,email.body_text.indexOF("Desc !1000000000!:")+79);

needs to at least be

var subjectforabend = email.body_text.substr(email.body_text.indexOf("Desc !1000000000!:")+19,email.body_text.indexOf("Desc !1000000000!:")+79);

Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

View solution in original post

5 REPLIES 5

Brent Sutton
Mega Sage

Hi Bob,

Can you please try the following on the second line of your insert script:

current.short_description = email.body.!1000000000!;

or

current.short_description = email.body.Desc!1000000000!; //the other parameters don't have spaces between them. I assume the description parameter should actually be Desc!1000000000!

If my suggestion works you can get rid of

"var subjectforabend = email.body_text.substr(email.body_text.indexOF("Desc !1000000000!:")+19,email.body_text.indexOF("Desc !1000000000!:")+79);"

from your inbound email action.

More information about setting fields from the email body can be found on ServiceNow docs.

Let me know if this worked for you.

Brent

P.S. If my suggestion helped then please mark as helpful and/or correct so other community members can benefit from this information.

 

Hi Brent,

 

I tried to use current.short_description = email.body.!1000000000!; but I an getting errors. It assume it does not like the exclamation points.

 

Allen Andreas
Administrator
Administrator

Initial issue I see is formatting:

var subjectforabend = email.body_text.substr(email.body_text.indexOF("Desc !1000000000!:")+19,email.body_text.indexOF("Desc !1000000000!:")+79);

needs to at least be

var subjectforabend = email.body_text.substr(email.body_text.indexOf("Desc !1000000000!:")+19,email.body_text.indexOf("Desc !1000000000!:")+79);

Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Hi Allen,

 

Thank you! The formatting was the issue. I updated the formula to "var subjectforabend = email.body_text.substr(email.body_text.indexOf("Desc   !1000000000!:")+20,59);" and it works like a charm!

 

Appreciate the help!!