create catalog request item through inbound email action

nilesh_patel
Kilo Explorer

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!!

 

6 REPLIES 6

The Machine
Kilo Sage

Check out this post, it leverages the Cart API and saves the hassle of manually building the REQ, RITM, and running the workflow.

https://community.servicenow.com/community?id=community_question&sys_id=bfa7f9c1dbc6ebc0d6a102d5ca96...

AbdulAzeez
Mega Guru

Nilesh,

 

I would recommend you to try using CART API with which you can raise a Request, RITM & triggers workflow.

 

Below is the sample Script you can use.

 

createRequest();
function createRequest() {
var cart = new Cart();
// add in cart, substitute your catalog item sys_id
var item = cart.addItem('00000000000000000000000000000000');
// set requested for, substitute your requested for
//Set Variables in your Cart Item - item, variable_nmae, parameter
cart.setVariable(item, 'requested_for', '00000000000000000000000000000000');
cart.setVariable(item, 'request_short_description', email.subject.toString());
cart.setVariable(item, 'request_description', email.body_html);
cart.setVariable(item, 'request_type', 'others');
var cartmsg = "received from: " + email.origemail + "\n\n" + email.body_text;
cart.setVariable(item,'comments',cartmsg);
var rc = cart.placeOrder();
}