How to parse name:value pairs in inbound mail Flows

Stefan Reichelt
Tera Guru
Tera Guru

Hi all,

 

I've seen posts from the past, but maybe something changed in the meantime: Are there any new solutions for parsing name:value pairs in inbound mail bodies which are supposed to be handled by an inbound mail triggered Flow instead of a classic Inbound Action?

 

Best regards

1 ACCEPTED SOLUTION

Stefan Reichelt
Tera Guru
Tera Guru

Thanks a lot for helpful answers. Eventually, I solved it using a custom action which can parse any input dynamically.

Snippet:

var reg = inputs.bodyText.split(/\r\n|\r|\n/); // reg becomes an array. 
var parsedObj = {};//split into 2d array
for(var i=0;i<reg.length;i++){
  reg[i] = reg[i].split(":");
  parsedObj[reg[i][0]]=reg[i][1];    
 }

It returns an object where I can access any of the parameters with a simple dot walking because the key is also the name of the parameter.

View solution in original post

5 REPLIES 5

Community Alums
Not applicable

Hi @Stefan Reichelt ,

 You can take help from this thread by referring Robert's video : https://www.servicenow.com/community/developer-forum/parsing-email-body-with-inbound-email-flows/m-p...

 

SoniaShridhar13
Giga Guru

Hi! @Stefan Reichelt You can try with below script -

gs.log("Values are "+email.body.corrective_action_follow_up+"---"+email.body.first_response_corrective_action);//check the actual values in the 1st line of inbound action

if (email.body.corrective_action != undefined){

current.u_first_response_corrective_action = email.body.first_response_corrective_action;

}

if (email.body.suspected_cause != undefined){

current.u_suspected_cause = email.body.suspected_cause;

}

if (email.body.corrective_action_follow_up != undefined){

current.u_corrective_action_follow_up = email.body.corrective_action_follow_up;}

 

Please mark it helpful if it helps..

Hi Sonia,

I want to achieve it within a Flow that is using the Inbound Mail trigger, not a classic Inbound Action. Do you think it's still achievable like this?

Hi! @Stefan Reichelt  

With Inbound Actions you could use something like "current.body.number", "current.body.something", to get the value on a line in your email body after for example "Number: ", "Something: ", etc..

I achieved this with Inbound Email Flows using below example-

fd_data.trigger.body.number;
fd_data.trigger.body_text.number;

Only this just returns null.

 

Please mark helpful if it helps...