Auto-generating Requests from emails

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-06-2010 01:11 PM
Is anyone auto-generating requests based on the content of an incoming email? We have a generic email address that we would like to forward to Service Now and auto-generate requests. Sounds simple enough, so I was hoping someone had already implemented.
Thanks for any help you can give me....
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-12-2010 05:49 AM
I have been working on a solution to this in my development environment. I haven't rolled it over to production yet but am happy to share what I have so far.
My implementation uses a rather tedious setup for the generic email address and inbound email rule but you can change these to suit your purpose.
Step 1: My generic email address sits in MS Exchange, for this example let's just say its create.req@mycompany.com. I gave myself full mailbox rights in Exchange to this mailbox and logged into it use Outlook to setup a rule to redirect all inbound email to this address to my SN instance. In the rule I changed the display name of my SN instance email to "createreq" but obviously kept the email address mycompany@service-now.com.
[The long story of why I did this: I know this seems silly, but the reason I did it this way is because we have the same type of rule that redirects all of our Service Desk emails into our instance. Whenever the SN instance receives the email via the redirect it sees the To: address as " To:mycompany@service-now.com". This meant that both of my Outlook/Exchange email rules would look the same coming in even though it was two different email addresses internally. By changing the display name the SN instance now sees the inbound email from my request email address as "To:"createreq" mycompany@service-now.com". This helps me identify which email redirect the message is coming from. I'm not claiming that this is the best way, it's just the way I did it.]
Step 2: Setup a new inbound email rule to look for your request emails and process them. System Policy>Email>Inbound Actions.
Name: Whatever you want, mine is "Create Request"
Type: New
Target Table: Shopping Cart [sc_cart]
Condition: email.direct.toLowerCase().indexOf('createreq') >= 0
//This is where the Outlook/Exchange redirect display name change helps identify where the email is actually coming from.
NOTE: I also had to add a condition to the New incident inbound email action of email.direct.toLowerCase().indexOf('createreq') == -1 so it didn't create an incident along with my request.
Script:
//get the user object from the From: email address
var sid = new GlideRecord('sys_user');
sid.get('email', email.from);
//this gets the location of the user, which is something we use in the request
var loc = new GlideRecord('cmn_location');
loc.get(sid.location);
gs.include('Cart');
//checks the email subject for request type, this allows you to use the same inbound action for multiple request types
//this one is for a loaner hard drive
if(email.subject.toLowerCase().indexOf('hard drive')>=0){
//create a cart
var hddcart = new Cart();
//add your requested item to the cart by sys_id of the catalog item
var item = hddcart.addItem('1f7561070a0a3c45003f57fc0e7da4e6', 1);
//fill in all of your required variables for the catalog item form
hddcart.setVariable(item, 'requested_for', sid.sys_id);
hddcart.setVariable(item, 'site', loc.name);
hddcart.setVariable(item, 'country', loc.country);
hddcart.setVariable(item, 'equ_type', 'harddrive');
//you can also have users put variables in the body of their email
//then use the commented example to fill your request item variable
//if(email.body.loan_start != undefined){
//hddcart.setVariable(item, 'loanstart', email.body.loan_start);
//}
hddcart.setVariable(item, 'loanstart', '2010-05-10');
hddcart.setVariable(item, 'loanend', '2010-05-15');
hddcart.placeOrder();
}
//you can then process other request items by using else if's below
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-18-2017 09:17 AM
Hi Jay,
But the target field in sys_email table is not getting set. Could you please mention the functionality related to this. I am not sure why this is happening.
Thanks,
Dedeepya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-20-2017 04:30 PM
I also notice that the target field in sys_email does not get set when using this functionality, and further, I get errors on the inbound action saying that the inbound rule was skipped when in fact, it actually runs and works as expected.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-05-2018 01:12 PM
Perfect. The Request variables got populated. But how do I assign values to Requested Item table fields from your script?