Inbound Email A ction to Custom variable

Tyler Johnson
Tera Expert

Hello Guys, I was attempting to pull a specfic line after the last : that starts with 

"UniqueFailureID="  from the email body text. I tried the below code but i couldnt get it to populate after the incoming email. any suggestions to my code? 
 
var emailBody = email.body.text;
var regex = /UniqueFailureID=.*:([a-f0-9\-]+)$/m;
var match = emailBody.match(regex);
 
if (match && match[1]) {
    var uniqueFailureID = match[1];
    current.u_uniquefailureid = uniqueFailureID;
    current.update();
} else {
    gs.log("UniqueFailureID not found in the email body for incident: " + current.number, "Inbound Email Action AAC_Automation");
}
 
1 ACCEPTED SOLUTION

Maddysunil
Kilo Sage

@Tyler Johnson 

Can you log the email body to inspect the content you getting in that, Also Depending on the format of your email body, you might need to adjust the regular expression. For instance, if there could be whitespace characters around the = sign or the : sign, you might want to make the expression more flexible.

Please try the updated code below:

 

var emailBody = email.body_text;
gs.info("Email Body: " + emailBody); // Log the email body to inspect its content

// Adjusted regular expression to be more flexible
var regex = /UniqueFailureID\s*=\s*.*:([a-f0-9\-]+)$/im;
var match = emailBody.match(regex);

if (match && match[1]) {
    var uniqueFailureID = match[1];
    current.u_uniquefailureid = uniqueFailureID;
    current.update();
} else {
    gs.log("UniqueFailureID not found in the email body for incident: " + current.number, "Inbound Email Action AAC_Automation");
}

 

 

lease Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks

View solution in original post

6 REPLIES 6

This worked, Thank you sir, i was able to get the info populated into the variable. 

Amit Verma
Kilo Patron
Kilo Patron

Hi @Tyler Johnson 

 

Probably, it's an issue with your email body. May be a whitespace is creating a problem. I tried your script on my PDI with a sample email body and it is working as expected. Refer below screenshots :

 

AmitVerma_0-1709005454171.png

 

AmitVerma_1-1709005472016.png

 

Can you try to log the email body and see if you are getting it as expected or not ? 

 

Thanks & Regards

Amit Verma


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