Using an inbound email action script, how can I map values from the email to a field in servicenow?

Tyler Michals
Kilo Guru

A user fills out a form and clicks submit via webpage.

An email is sent to our instance and creates an incident.

This is what a portion of that inbound email looks like:

First Name: John

Last Name: Smith

Employee Contractor Id: 8675309123

Email Address: john_smith@yahoo.com

I would like to take the email address provided in the body of the email and map it to the "caller_id" field in service now.

Currently I am using this script and it is not working:

if (email.body.Email_Address != undefined)

    current.caller_id = email.body.Email_Address;

Please Help!

10 REPLIES 10

Hi tmichals,



What was the script that worked for you?



I'm working on a similar requirement, the username is in the body of an email from an unknown mailbox and I need to take a string, extract the username and use it to assign the caller_id.



Be very grateful if you could share each step of your solution.



Thanks!


In order for the script to work, the user has to already be built in servicenow, the FROM email address has to be static, and every email must have the same general template. An example of the inbound email would be:



To: test@service-now.com


From: static@gmail.com                 <---- every email would have to be from this same address



First Name: John


Last Name: Smith


Username: jsmith123                         <---- already a user on the sys_user table



In the inbound email action, use this script:



current.caller_id = email.body.username;



That script will look for the value after [Username:] in the email body, and map that value to the caller_id reference field.



Also, static@gmail.com would have to be built on the sys_user table with roles that allow it to write to the incident form.


This is the script I ended up using:



if (email.body.email != undefined)


    current.caller_id = email.body.email;


Reghuram
Kilo Expert

Caller_id is reference ..so it wont work.. I think you may have to parse email.body_text and extract   the 'email Id' ( value ) and get it assigned to current.caller_id.


derek_young
Kilo Contributor

I would probably use a regex script to pull out the information after "Email Address:"


Ex.


var email = /\Email Address: (\S+@\S+);



if(email.body_html.search(email) >= 0)


  {


//do something


  }



thats the jists of it