Extract customer from body of email
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-07-2012 04:20 PM
We currently have a SharePoint form that our users have to request changes to our corporate web site. Since not all of our divisions use SNC, SharePoint is the best option for providing this request intake. Once the form is completed it emails our instance with the change info. I've created an inbound email action to extract the subject and body of the email to populate the form but I'm unable to determine the Requested by since the email comes from the SharePoint server and not the user that submitted the form. However, the body of the email does include on the first line:
Requested by: lastname, firstname.
I'm unsure how to extract this, and convert it into the userID in SNC so that we don't have to manually change the requested by field in the change every time. This is the first line in the body of the message, and the only info on that line but I just can't seem to find anything online to poach for the script to extract this info and convert to user ID.
Thanks,
Nate.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-09-2012 07:03 AM
You are likely going to need to use regular expressions to parse out the Requested By line and take the lastname and first name to generate your user ID. Of course, your user ID's need to be in a format that takes Username and Firstname and combines them into a predictable username.
Let's say that the Requested By Line in an email looks like this:
Requested by: Andersen, John.
Let's also assume that the username convention for your servicenow instance is:
firstname.lastname
You could have code that executes in the inbound email action that finds the Requested by line and grabes the First and Last name and generates the username in this manner:
var pat = /^Requested by\:\ (.*)\,\ (.*)\.$/mg
var tokens = pat.exec(email.body_text);
var username = "";
if(tokens && tokens.length == 3){
username = tokens[2]+"."+tokens[1];
gs.log("Username: " + username);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-22-2012 06:41 PM
Hi John,
I am also trying to do same thing. I have created my own Inbound action with help of regular expression above. Here is my code :
************************************************************
var CustName = /^Customer Name\:\ (.*)\ (.*)$/gm;
var tokens = CustName.exec(email.body_text);
var username;
if (tokens && tokens.length == 3){
username = tokens[1]+" "+tokens[2];
current.u_request_status = 'New';
gs.log("Username: " + username);
}
current.u_customer_name = username;
current.insert();
************************************************************
Above code successfully creating new request, but it is not inserting value for filed u_customer_name. I did some testing and found in above code if condition failing.
My email contains customer Name like :
Customer Name: Testing Request
If if hardcode this customer name this script is working fine. For ex. if I relapace var tokens = CustName.exec(email.body_text); with var tokens = CustName.exec("Customer Name: Testing Request"); I will get the customer name populated in the appropriate field.
Could you please help me where I am making mistake.
ND
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-15-2013 04:19 AM
Needed to extract firstname and lastname from forwarded internal email which has had SMTP address removed, needed to reassemble our SMTP company address for one or two names. Couldn't get suggestions to work. Did this which works...
INSIDE AN INBOUND EMAIL ACTION FOR FORWARDED EMAIL...
// ....all your usual stuff here....
//mods begin...
var findname = email.body.from;
var testATexists = findname.indexOf('@');
if (testATexists < 1){
var tokens = new Array ();
tokens = findname.split(" ");
var userinitial;
var EmailUserName;
var emailusername;
if (tokens && tokens.length == 2){
userinitial = tokens[0].charAt(0);
EmailUserName = tokens[1]+userinitial+"@yourcompany.com";
emailusername = EmailUserName.toLowerCase();
current.caller_id = gs.createUser(emailusername);
}
if (tokens && tokens.length == 1){
EmailUserName = tokens[0]+"@yourcompany.com";
emailusername = EmailUserName.toLowerCase();
current.caller_id = gs.createUser(emailusername);
}
}
//...end mods
// ....all you usual stuff here....current.insert(); etc....