Create catalog request through email inbound

jamesgo
Giga Contributor

I have a requirement to auto-create catalog request through email inbound action, my approach is to use the Cart API(any better solution?) in inbound action script, I set up the inbound on sc_req_item table but I am not doing a current.insert() otherwise it will double submit the request(as the order is already placed through Cart API), things working fine but one problem I don't find a way to attach the original inbound email to the Activity field, any idea?

1 ACCEPTED SOLUTION

Here are some ideas:



Option 1: Add Message to Comments



Inbound Action: Create Requested Item


Table: sc_req_item


Condition: <your condition here>


Script:


createRequest();


function createRequest() {


  var cart = new Cart();


  // add in cart


  var item = cart.addItem('8c2a069c242cb800839dec45b40a7496');


  // set requested for


  cart.setVariable(item, 'requested_for', '5136503cc611227c0183e96598c4f706');


  cart.setVariable(item, 'request_short_description', email.subject.toString());


  cart.setVariable(item, 'request_description', email.body_html);


  cart.setVariable(item, 'request_type', 'others');


  // set application


  cart.setVariable(item, 'application', '3243d574bd05300071578913764fb117');


  // set assignment group


  cart.setVariable(item, 'assignment_group', '4769d53099266800d7ea6843423a4c2b');


  cart.setVariable(item, 'priority', 'PR3');


  var cartmsg = "received from: " + email.origemail + "\n\n" + email.body_text;


  cart.setVariable(item,'comments',cartmsg);


  var rc = cart.placeOrder();


}




Option 2: Generate without Cart API



Inbound Action: Create Requested Item


Table: sc_req_item


Condition: <your condition here>


Script:


createRequest();


function createRequest() {


      //Create Request


      var grRequest = new GlideRecord ("sc_request");


      grRequest.initialize();


      grRequest.requested_for = '5136503cc611227c0183e96598c4f706';


      grRequest.short_description = email.subject.toString();


      grRequest.description = "received from: " + email.origemail + "\n\n" + email.body_text;


      var requestSysId = grRequest.insert();


      //Create Request Item


      current.requested_for = '5136503cc611227c0183e96598c4f706';


      current.short_description = email.subject.toString();


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


      current.cat_item = '8c2a069c242cb800839dec45b40a7496';


      current.parent = requestSysId;


      current.request = requestSysId;


      current.request_type = 'others';


      current.application= '3243d574bd05300071578913764fb117';


      current.assignment_group='4769d53099266800d7ea6843423a4c2b';


      current.priority= 'PR3';


      current.insert();


}



I tested Option 2 and it did work for me.   I used a different Catalog Item (Dev Laptop), because I didn't have your item in my catalog, but most everything else worked the same.Capture.PNG


View solution in original post

48 REPLIES 48

prashantdharne
Tera Contributor

Hey Mike,



I tried the same code but the workflow is not getting attached to the RITM. Would you be able to help me out here?




current.sys_domain = 'bf937fe85d184a00efdee878eb0dc7fd';



var grRequest = new GlideRecord ("sc_request");


grRequest.initialize();


grRequest.requested_for = '7ff82bdee07f0ec021c9cd2218ba7aa6';


grRequest.short_description = email.subject.toString();


grRequest.description = "received from: " + email.origemail + "\n\n" + email.body_text;


grRequest.sys_domain = 'bf937fe85d184a00efdee878eb0dc7fd';


grRequest.company = 'bf937fe85d184a00efdee878eb0dc7fd';



var requestSysId = grRequest.insert();



//Create Request Item



current.requested_for = '7ff82bdee07f0ec021c9cd2218ba7aa6';


current.short_description = email.subject.toString();


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


current.cat_item = 'e9500a3f0fabc200277022d8b1050e3b';


current.parent = requestSysId;


current.request = requestSysId;


current.assignment_group='3ee349ce0f864600b493db0be1050e86';


current.stage ='request_approved';


current.insert();



var w = new Workflow();


wfSysId = w.getWorkflowFromName("General Service Request V1");


w.startFlow(wfSysId, current, current.operation());


pratulagarwal
Mega Expert

Hi,



I have faced a similar issue and realized that using the cart API is a better option, as in that case we just need to populate the catalog variables and submit the catalog.


It is similar to creating a request in the tool. And REQ, REQ ITEM, TASK, APPROVALS, and WORKFLOW association all will be taken care by the tool it self.



Regards


Pratul


yeskaytee
Kilo Contributor

Hi,



Thank you for this post.


I have been using catalog item to get all details related to a request.


However, I now want request to be generated trough inbound email action.



How do i get the values from email and set them into RITM variable editor?



Example:


If email has


Name : First Last


Start Date : 12/3/2016


Location : 123 City


(These above fields were in the catalog request form)


You want to set this values into Request item...


Did you ever get the above variables to populate? I am interested in achieving the same. Today, I'm only getting the email content to populate in description; the defined variables aren't working.