Inbound Email Action: Setting Field Values from the Email Body where name has a space

jmoreau
Mega Contributor

I am using an inbound action to parse the body of the email.   I have done this fine for strings and where the name of the name/value pair is one word.   However, I am unable to figure out how to parse it when the name is separated by a space.

Two questions:

1) How to parse where name has spaces?

2) How to insert into a Date type field?

Email Example
<Body>

Pricing Effective: 04/11/2017

</Body>

Inbound Action Script

current.u_my_custom_date_field = email.body."Pricing Effective";

1 ACCEPTED SOLUTION

Ignore the previous one.


The Date format should be same as system date format



var mydate = email.body_text.indexOf('Pricing Effective: ');


var gDate = new GlideDate();


gDate.setValue(mydate);


gs.info(gDate);



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

View solution in original post

10 REPLIES 10

Now that I tried it, I'm marking yours as correct.   Setting the field as a Date works perfect, however, pulling the result for a 2 worded label is close but not correct.   If I use the index of, it was displaying a numeric value.   In my case it was showing 197.   So this must be literally showing the index of the string.     I finally found on another post that the correct way to pull a 2 worded label is just doing email.body.<name> but if the label is two worded, replace the space with the underscore.   That did the trick





Below is what works:




<Email Body>


      Pricing Effective: 06/11/2017



<Inbound email action>


  var gDate = new GlideDate();


  gDate.setValue(email.body.pricing_effective);


  current.u_pss_pricing_effective_date = gDate;


  gs.info("Pricing Date from email: " + gDate);




Other post:


Finding text in emails - inbound email actions


I am trying to accomplish something similar... The email coming into the system will contain the following line and I need to input the value into a field on the item being created. 

Application Name : ServiceNow

I used email.body_text.indexOf('Application Name : '); but the system is giving the character position instead of the value. 

find_real_file.png

Any ideas??

You need to use email.body.application_name


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

Ah ok! Thanks for the quick reply 🙂

You just need to use email.body.pricing_effective, as per SN docs:

Setting field values from the email body (servicenow.com)