The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Inbound Email Action to Parse Email Body to Search for a User ID and Group

Beto
Mega Guru

I am trying to pull "name" and "group" from an inbound email that gets send from another ticketing system. User ID would be the caller and group is the assignment group. Please see below on the code. I am pulling "User ID" to get the name of the caller. And pulling "Current Assignees:" for assignment group. Currently it is coming out as guest as caller.

var userIdWithExtraChars = bodyVariable.substring(bodyVariable.lastIndexOf(") by") + 11, bodyVariable.lastIndexOf(") by") + 41);

current.caller_id = email.body.user_name;

if (email.body.assignees != undefined)

current.assignment_group.setDisplayValue(email.body.assignees);

Here is the email:

Body

Notification of Work Order Registration

Work Order:PC Not Working
Work Order Number:79032

Additional Comments:

Entered on 10/27/2017 at 20:29:54 PDT (GMT-0700) by Jane Brown

The PC is not working and is plugged in.

Current Assignees: Desktop Support

Customer Information:

User ID:smithj
1 ACCEPTED SOLUTION

Hi Bryant ,


Did you try:


current.caller_id.setDisplayValue(email.body.user_id);



By the way, I have not had luck using spaces in the email body, so for example, "User ID" did not work, but "user_id" did.


In your email, you have User ID with a space.


harel


View solution in original post

7 REPLIES 7

oharel
Kilo Sage

Hi Bryant,



What's coming as guest? the user id?


Did you try:


current.caller_id.setDisplayValue(email.body.user_name);



By the way, I have not had luck using spaces in the email body, so for example, "User ID" did not work, but "user_id" did.


harel


richard-service
ServiceNow Employee
ServiceNow Employee

I am not clear exactly what you are asking for.   You have described what you're attempting to accomplish, but can we get more detail on the error you're seeing and the question you are asking?



Also, can you post your code so we can see what you're doing.   The snippets you posted weren't very helpful.  



One thing, I would look into leveraging regular expressions instead of the indexOf method.   As your string lengths are not guaranteed to be the same length in an email.


Here is the entire code. It is coming in as guest for the caller. I want to use the below user ID and search against servicenow for the caller.




// Note: current.opened_by is already set to the first UserID that matches the From: email address



current.comments = "received from: " + email.origemail + "\n\n" + email.body_text;


current.short_description = email.subject;


current.description = email.body_text;


current.category = "request";


current.incident_state = IncidentState.NEW;


current.notify = 2;


current.contact_type = "email";



var userIdWithExtraChars = bodyVariable.substring(bodyVariable.lastIndexOf("User ID: ") + 11, bodyVariable.lastIndexOf("User ID: ") + 41);


//keeping in mind length of userid doesnt go beyond 30 chars.


var userId = userIdWithExtraChars.substring(0 , userIdWithExtraChars.lastIndexOf("\nDate"));



//in my case i would require to glide the user table to search for the user, not sure how "Date" can be brought to user for my scenario


current.caller_id = email.body.user_id;



if (email.body.state != undefined)


    current.state = 6;



if (email.body.assignees != undefined)


current.assignment_group.setDisplayValue(email.body.assignees);



current.insert();



}


Hi Bryant ,


Did you try:


current.caller_id.setDisplayValue(email.body.user_id);



By the way, I have not had luck using spaces in the email body, so for example, "User ID" did not work, but "user_id" did.


In your email, you have User ID with a space.


harel