- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-07-2022 10:55 PM
Hi all,
I am having issue with the below inbound action not creating request with using cart api, and the inbound action logs shows this message "did not create or update sc_request using current"
I have confirmed the right catalogue item sysid is used and active, i have added "any user" user criteria as described in couple other post - but still no request.
(function runAction(/*GlideRecord*/ current, /*GlideRecord*/ event, /*EmailWrapper*/ email, /*ScopedEmailLogger*/ logger, /*EmailClassifier*/ classifier) {
var reqForID;
if(email.body.requestor != undefined){
//cart.setVariable(item, 'preferred_name', email.body.requestor);
var user_rf = new GlideRecord("sys_user");
user_rf.addQuery("name", email.body.requestor);
user_rf.addActiveQuery();
user_rf.query();
if(user_rf.next()){
reqForID = user_rf.getUniqueValue();//if user found, get ID to pass to cart so Requested for will be generated
gs.log("found: "+reqForID);
}
}
if(reqForID){
var cartId = GlideGuid.generate(null);
//When you create the a cart object by calling the Cart API, the user sys_id you pass in becomes the request's "Opened by" user - NOT Requested For
var cart = new Cart(cartId, reqForID);
var tempCart = GlideappCart.getCartForRhino(cart.cartName, cart.userID);
//Now we can set the requested_for user on the temp cart
tempCart.setRequestedFor(reqForID);
// Make the tempcart the cart's cart
cart.cart = tempCart.getGlideRecord();
var item = cart.addItem('b8224947db683410855d3632f3961945'); //my cat_item
cart.setVariable(item, 'subject', email.subject);
cart.setVariable(item, 'body', email.body_text);
cart.update();
var rc = cart.placeOrder();
// Workaround to set target to REQ
sys_email.instance = rc.sys_id;
sys_email.target_table = rc.getTableName();
sys_email.update();
var reqGr = new GlideRecord('sc_request');
reqGr.addQuery('sys_id', rc.sys_id);
reqGr.query();
if (reqGr.next()) {
reqGr.short_description = email.subject;
reqGr.description = email.body_text;
reqGr.update();
}
}
event.state = "stop_processing"; // to stop processing any further inbound actions
})(current, event, email, logger, classifier);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-07-2022 11:07 PM
Hi
the used api Cart() is outdated and is recommended to use the new api CartJS(). See https://developer.servicenow.com/dev.do#!/reference/api/sandiego/server/sn_sc-namespace/c_CartJSScop...
Maik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-07-2022 11:07 PM
Hi
the used api Cart() is outdated and is recommended to use the new api CartJS(). See https://developer.servicenow.com/dev.do#!/reference/api/sandiego/server/sn_sc-namespace/c_CartJSScop...
Maik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-07-2022 11:11 PM
ok Thanks for the info i will change.