Inbound Action using Cart JS

purdue
Kilo Sage

Hello,

I was able to write successfully  an inbound action using cart api but have been told it must be converted to Cart JS due to Cart API being deprecated.   I have tried the example below but no luck. All and any assistance is welcomed. Thanks, Chad

  1. First of all it appears the variables cannot pass in any but strings.   So how will the variables be updated to follow Cart API?  
  2. How can I populated Requested_For without hardcoding sys_id?
  3. Can I SubmitOrder without adding to cart?

Original Inbound Action using Cart API

createRequest();
function createRequest() {
if (gs.getProperty("sn_hr_core.inbound_email_wbd_domains").toLowerCase().indexOf(email.origemail.split('@')[1].toLowerCase()) > -1) {
var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
var item = cart.addItem('70e9b1c01b2912d08d722f4b234bcb9a');
var sid = email.from;
var req = "420287b11b2cb910783f43b1b24bcb8a"; // Guest User
var reqFor = new GlideRecord('sys_user');
reqFor.addQuery('email',sid);
reqFor.query();
if (reqFor.next()){
cart.setVariable(item, 'requested_for', reqFor.sys_id);
}
else{
cart.setVariable(item, 'requested_for', req);
}
cart.setVariable(item, 'short_description', email.subject.toString());
cart.setVariable(item, 'description', "From Email Address: " + email.from.toString() + '\n' + "Email Body: " + email.body_text.toString());
var rc = cart.placeOrder();
 
Cart JS
var cart = new sn_sc.CartJS();
var item = {
'sys_parm_id': '0e9b1c01b2912d08d722f4b234bcb9a',
'sysparm_quantity': '1',
'variables':{
'short_description': email.subject.toString(),
'description': "From Email Address: " + email.from.toString() + '\n' + "Email Body: " + email.body_text.toString(),
'requested_for': 'reqFor.sys_id',
}};
var CartDetails = cart.orderNow(item);
gs.info(CartDetails);
0 REPLIES 0