create catalog request item through inbound email action
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2019 01:25 PM
Apologies in advance, but I'm very new in scripting in general and building within SN.
I have a catalog item setup with no cart, no order, and no proceed checkout. I need to setup an Inbound Action to able to create this REQ and RITM for that item by email. I've looked at and tried number of scripts found on many of forums here but I just can't seem to get this to work. Would someone mind helping out?
I'm pretty sure the script I've found and tweaked is all off but posting anyways.
createRequest();
function createRequest() {
//Create Request
var grRequest = new GlideRecord ("sc_request");
grRequest.initialize();
//substitute your requested for
grRequest.requested_for = '00000000000000000000000000000000';
grRequest.short_description = email.subject.toString();
grRequest.description = "received from: " + email.origemail + "\n\n" + email.body_text;
var requestSysId = grRequest.insert();
//Create Request Item, substitute your requested for
current.requested_for = '00000000000000000000000000000000';
current.short_description = email.subject.toString();
current.description = "received from: " + email.origemail + "\n\n" + email.body_text;
//substitute your cat item
current.cat_item = '00000000000000000000000000000000';
current.parent = requestSysId;
current.request = requestSysId;
current.insert();
//Workflow Trigger
//More information http://wiki.servicenow.com/index.php?title=Workflow_Script
var w = new Workflow();
wfSysId = w.getWorkflowFromName("workflow.name.here");
w.startFlow(wfSysId, current, current.operation());
}
Thanks in advance!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2019 01:46 PM
Good evening,
I have an inbound email rule that creates a leaver request which comes in from application. It looks very similar to your script so might be worth just comparing. What I would also say is check the conditions on your inbound email. What caught me out with ours was that the email was actually defined as forwarded, so I had to make sure my condition allowed for emails being forwarded.
Also check the email that has come into your system. If it says that the inbound email action has been skipped then your condition is off. If it says processed and nothing has been created chances are its your code. (can you tell I'm also new... hope it helps)
function createRequest() {
var grRequest = new GlideRecord ("sc_request");
grRequest.initialize();
grRequest.requested_for = sys_email.user_id;
grRequest.short_description = email.subject.toString();
grRequest.description = "received from: " + email.origemail + "\n\n" + email.body_text;
var requestSysId = grRequest.insert();
current.requested_for = '';
current.short_description = email.subject.toString();
current.description = "received from: " + email.origemail + "\n\n" + email.subject.toString() + "\n\n" + email.body_text;
current.cat_item = 'SYS_ID OF THE CATALOG ITEM';
current.parent = requestSysId;
current.request = requestSysId;
current.request_type = 'others';
current.application= '';
current.assignment_group='';
var w = new Workflow();
wfSysId = w.getWorkflowFromName("EXACT WORKFLOW NAME");
w.startFlow(wfSysId, current, current.operation());
current.insert();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2019 02:09 PM
Thanks, Darren. I'm in the process of comparing now.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2019 11:35 PM
I target the sc_request table and it works all fine
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2019 07:31 AM
You were right about the condition. That got the inbound email to create a REQ, but there were duplicates and neither had a RITM created.