The CreatorCon Call for Content is officially open! Get started here.

Inbound email to get values from the users email body

Mr_X1
Tera Contributor

Hello Developer,

This would be the email body from client,

* Yellow marked 6 lines should be the updated in the worknotes/comment when incident is created via inbound email.
* Red Arrowed " Blue selected " : User ID should be selected as caller field & Opened by field in the incident created via inbound email.

Can someone please help on this, How to achive this task ?

 

find_real_file.png

8 REPLIES 8

Jaspal Singh
Mega Patron
Mega Patron

Hi,

 

Try below in your inbound mail action

var bodyis=email.body_text; //This gives you complete body of email

var getrequiredtextstart=bodyis.split('worked on immediately,')[1]; //This gives you text after worked on immediately text

var getrequiredtextend=getrequiredtextstart.split('Issue:')[0];//This gives you text before Issue: keyword

current.work_notes=getrequiredtextend; //This is final yellow text

var useris=email.body.UserId;//will give you James1234

var setuser=new GlideRecord('sys_user');

setuser.addQuery('user_name',useris);

setuser.query();

if(setuser.next())

{

current.caller_id=setuser.sys_id;

current.opened_by=setuser.sys_id;

}

 

thank yu, Sure i'll try this once quickly and update you

Willem
Giga Sage
Giga Sage

You can access the values in an inbound action like so:

email.body.description

email.body.dns_name

email.body.ip_address

email.body.plant

email.body.location

 

email.body.userId

 

So to set worknotes:

var worknotesStr = "The test information as follows:\n";

worknotesStr+= "Description:" + email.body.description + " \n";

worknotesStr+= "DNS Name:" + email.body.dns_name+ " \n";

//etc

 

current.work_notes = worknotesStr;

 

 

Also refer to:

https://docs.servicenow.com/bundle/paris-servicenow-platform/page/administer/notification/reference/...

 

Mr_X1
Tera Contributor

thank you, Sure i'll try this once quickly and i'll update you