How to parse "Employee Name" from Email Body Text via a Inbound Action to Caller field?

Nathan Okh
Mega Sage

Hello Community,

I have found many articles on this, and none have figured this out for me. So we need to parse "Employee Name" == "[user name]" into the Caller field in an incident. 

The email HTML that comes in is:

<tr>
<td valign="top" style="font-weight: bold;padding-top:10px;padding-bottom:10px;border-bottom: 1px solid #E6E6E6; width: 100px;">Employee Name</td>
<td width="25px" ;="" style="border-bottom: 1px solid #E6E6E6;"></td>
<td style=" padding: 10px 5px 10px 5px; border-bottom: 1px solid #E6E6E6; font-family:Arial,'Segoe UI Emoji','Segoe UI Symbol';  font-size:10pt;  color:#000000;  font-weight:normal;  font-style:normal;  text-decoration:none;  background-color:#FFFFFF;padding-left:8px; font-weight:bold;  background-color:#FEFF85; ">Nathan Test 2</td>
</tr>

This is how it looks in the body of a received incident:

find_real_file.png

 

So far I've tried a number of things and they haven't worked.

My current Inbound Action: Action stands here:

find_real_file.png

Any help will be much obliged! I will mark helpful etc!

1 ACCEPTED SOLUTION

Nathan Okh
Mega Sage

Hey Community. Would love some more help if possible.

 

I did try this, this was very helpful:

https://community.servicenow.com/community?id=community_article&sys_id=8dcdc538db50ccd0d82ffb2439961...

Here I essentially used it to do some "email processing" so that I can get a big lumpy string of characters and used it to test. Once i was able to get the exact variables I needed I disregarded the indesReg and finalvalue steps...

 

I need this to now populate the "Caller" reference field. But, i'm having no luck. 

Now, this looks like this:

(function runAction(/*GlideRecord*/ current, /*GlideRecord*/ event, /*EmailWrapper*/ email, /*ScopedEmailLogger*/ logger, /*EmailClassifier*/ classifier) {
	
//Processing Email HTML - TEST1
	var htmlcode=email.body_html; 
	htmlcode = htmlcode.replace(/<style([\s\S]*?)<\/style>/gi, '');
	htmlcode = htmlcode.replace(/<script>/gi, '');
	htmlcode = htmlcode.replace(/<\/div>/ig, '\n');
	htmlcode = htmlcode.replace(/<\/li>/ig, '\n');
	htmlcode = htmlcode.replace(/<li>/ig, '  *  ');
	htmlcode = htmlcode.replace(/<\/ul>/ig, '\n');
	htmlcode = htmlcode.replace(/<\/p>/ig, '\n');
	htmlcode = htmlcode.replace(/<br\s*[\/]?>/gi, "\n");
	htmlcode = htmlcode.replace(/<[^>]+>/ig, '');
	htmlcode=htmlcode.replace('  ','');
	htmlcode=htmlcode.replace(/\r?\n|\r/g,'');
	gs.log("final email String  "+htmlcode);
//ends processing
	var indesREG = new SNC.Regex('/Employee:.*Request Received/si');  // this line will get the value of string between Employee Name and Request Received
//do not use finalvalue, the above processing is good enough to collect the employeename natively.
	var finalvalue = indesREG.match(htmlcode).toString();
	
	
	

//test 1b - This will get the correct data.
var employee_name = email.body.employee;	
	
//populate the caller reference field...
current.caller.setDisplayValue(employee_name); //does not work!! what the heck

//populate a string field for testing
current.u_reentry_caller=employee_name;
//the rest of the journey
current.comments = "Email received from: " + email.origemail;
current.short_description = email.subject + ' test1 ' + employee_name; 
current.description = email.body_text;

View solution in original post

8 REPLIES 8

Ishaan Shoor
Mega Sage
Mega Sage

I have done something similar to create a request from an inbound email and map the user from the email.

Please find the code below. You can modify this code as per your requirement for create a incident and map the caller field as I've done worker to employee in the code below.

 

createRequest();

function createRequest() {

var cart = new Cart(); //calling the cart API

var item = cart.addItem('item_sys_id');

// set variables
var worker = email.body.exiting_worker_name;

var userRec = new GlideRecord("sys_user");
userRec.addQuery("name", worker);
userRec.query();
if (userRec.next()) {
var userID = userRec.getUniqueValue();
}


cart.setVariable(item, 'employee', userID);

var rc = cart.placeOrder();
var ritmSys = rc.number;

updateRITM(rc.sys_id); 

}

function updateRITM(req){

var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('request', req);
ritm.query();
while (ritm.next()){
ritm.description = email.body_text;
ritm.update();

}

}
event.state="stop_processing";

Hope this helps!
BR.
Ishaan Shoor

This looks interesting I'll have to try to implement this. Was this done in the Inbound Action level or else where?

Yes, this was done at the inbound action level.

Hope this helps!
BR.
Ishaan Shoor

I wasn't able to make that work for me 😞