- 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-07-2015 12:14 PM
Hi Mike,
I noticed in your script that you used setVariable for the Requested For field that is on the RITM.
cart.setVariable(item, 'requested_for', '5136503cc611227c0183e96598c4f706');
This does not work for our instance. Any idea why? I've tried updating this field using different methods client scripts, business rules, scripting through the WF, but none of them work. I eventually was able to update the Opened By field on the RITM using the following but it never updated the Requested For.
var fid = reqUser.sys_id.toString();
var cart = new Cart(cartId,fid);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-07-2015 01:16 PM
These are just examples, so your sys_id will be different on your instance. 5136503cc611227c0183e96598c4f706 is a sys_id of an user that worked on my instance, but you have different users and different sys_ids.
Hope that helps,
Mike
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-07-2015 01:54 PM
When I put a valid sys_id into that area it doesn't update though.
Our requested for field is from the sc_request table though.
I've tried using the following and it still doesn't set.
cart.setVariable(item, 'request.requested_for', '5136503cc611227c0183e96598c4f706');
cart.setVariable(item, 'sc_request.requested_for', '5136503cc611227c0183e96598c4f706');
cart.setVariable(item, 'request_requested_for', '5136503cc611227c0183e96598c4f706');
cart.setVariable(item, 'sc_request_requested_for', '5136503cc611227c0183e96598c4f706');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-07-2015 10:29 PM
Hi Karen,
We were also having this same issue before and was able to found some help on the community as well on what solution to use.
Currently on our instance, we are setting the requested for on Cart API using below script:
The script is added after all variables are defined and before the cart.placeOrde() command.
var cartGR = cart.getCart();
cartGR.requested_for = '0035fc376fda65c07ec428112e3ee461';
cartGR.update();
While for the workflow, we are using Run Script activity to add up below script:
var setReqFor = current.request.getRefRecord();
setReqFor.requested_for = '0035fc376fda65c07ec428112e3ee461';
setReqFor.update();
Hope it helps.
Thank you,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-08-2015 06:42 AM
This worked!! Thank you! I only ended up needing the inbound action script, though I'm sure the workflow script will help out in the future.