- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-25-2014 02:31 PM
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?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-27-2014 03:56 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-08-2015 08:28 AM
Hi Karen, so what did you inbound action script end up looking like? Can you post?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-08-2015 09:22 AM
See below. Updated two variables, one of them is a reference field. Line 34-36 is what I added to get the Requested For to update.
//1. Creates a new cart, with cartID as the name and the sys ID as the creator
var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
//2. Adds the form "WWG - Shared Drive" to the cart
var item = cart.addItem('e92a1d090f33f5009a1ba109b1050e2a');
//3. Sets a global variable for requested for
var rf;
//4. Looks through the body of the email for "User Id requesting Access:" and gets the value after it. It will then write it to the log
var myRequesterID = email.body.user_id_requesting_access;
gs.log('Requester id is: ' + myRequesterID);
//5. if the script found something
if(!myRequesterID.nil()){
//6. It will bring up all the records in the User table
var reqUser = new GlideRecord('sys_user');
//7. look only for the RACF ID as the username
reqUser.addQuery('user_name',myRequesterID);
reqUser.query();
//8. If it finds a matching username from the User table
if(reqUser.next()){
gs.log("has next ");
//9. It will bring back the sys ID for that user ID and write it to the log
gs.log(myRequesterID + "'s sys id is " + reqUser.sys_id);
//10. It then changes the sys ID into a string
var fid = reqUser.sys_id.toString();
//10. Variable question "racfid for whom the request is for:" is set to the sys ID/username/RACF ID
cart.setVariable(item, 'racfid',fid);
//11. Global variable is set to the sys ID/Username/RACF DI
rf=fid;
}
}
//12. Variable question "Please describe your request:" is set with the subject and contents of the email
cart.setVariable(item, 'details', "received from: " + email.origemail + "\n\n" + email.body_text);
//13. Gets the cart again and sets the Requested For on the Cart/RITM
var cartGR = cart.getCart();
cartGR.requested_for = rf;
cartGR.update();
//14. Submits the RITM/cart
var rc = cart.placeOrder();

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-06-2016 07:10 AM
I am trying to use this method for to setup a scheduled job to create a reoccurring request. We have some monthly processes that need the request filled out. Is there any reason that your solution above would not work in a scheduled job? The job I have created is create the REQ but not kicking off the item / workflow.
Thanks for the help!
-Chris

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-10-2020 03:48 AM
Life saver Solution for me thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-26-2015 02:44 PM
Hello Mike!
First off, big thanks to you and others for assembling this information.
I was going through this thread as I had a similar problem. I am using OPT 2, creating both REQ and RITM.. However, I CANNOT get the workflow to fire. I am positive I have the proper WF associated. I have the following condition on my 'Show Workflow' UI Action:
!current.cat_item.workflow.nil() && !current.context.nil() && gs.hasRole('admin')
I am not seeing the UI Action pop, indicating to me that the WF is not firing whatsoever. I do not see a resolution here to the workflow disconnect problem, rather 'make sure your have a WF associated to item'
I am hoping you can provide some insight.
Thank you very much.
-Darrin
Here is my script:
createRequest();
function createRequest() {
//Create Request
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();
//Create Request Item
current.requested_for = sys_email.user_id;
current.short_description = email.subject.toString();
current.description = "received from: " + email.origemail + "\n\n" + email.body_text;
current.cat_item = 'fb31a7780fb53500b0b246ace1050e9f';
current.parent = requestSysId;
current.request = requestSysId;
current.request_type = 'others';
current.assignment_group='92b67c5b0f86a100b0b246ace1050e41';
current.priority= '3';
current.insert();
}