In an email inbound action using CartJS() to order from a specific user's cart.

Ilo Gassoway
Mega Guru

I am building an inbound action to take an email from one of our automation tools and order a catalog item. in the email is the manager who I want to order the item from. However even if i add the setRequestedFor it still shows the email address ordered the item.  Suggestions?

 

//get Employee Object
var employeeCorpID = email.body.corpid;
var employee = new GlideRecord('sys_user');
employee.get('user_name', employeeCorpID);

//get Manager Object
var managerCorpID = email.body.manager_corpid;
var manager = new GlideRecord('sys_user');
manager.get('user_name', managerCorpID);


//order Item
var cart = new sn_sc.CartJS();
var item = {
    'sysparm_id': 'fd79407b1b95da10d40e2f05604bcb87',
    'sysparm_quantity': '1',
    'variables': {
        'submitted_by': manager.sys_id.toString(),
        'requested_for': employee.sys_id.toString(),
        'title': employee.title.toString(),
        'email': employee.email.toString(),
        'location': employee.location.toString(),
        'department': employee.department.getDisplayValue().toString(),
        'phone': employee.phone.toString(),
        'actions_needed': email.body_text
    }
};
var cartDetails = cart.addToCart(item);
cart.setRequestedFor(manager.sys_id.toString());
var checkoutInfo = cart.checkoutCart();
var req_id = checkoutInfo.request_id;
8 REPLIES 8

It would be nice if the cartJS api could allow it like the old cart api could. I am just trying to catch it before communications go out.

Emails are triggered by the event processor so it unlikely that the code will run so slowly that the event processor finishes before you code.

 

But I agree that it would be better to set the value as its created.

 

Sumanth16
Kilo Patron

Hi @Ilo Gassoway ,

 

Please refer below thread:

https://www.servicenow.com/community/developer-forum/cartjs-order-2-items-via-inbound-action/m-p/134...

 

Please hit like and mark my response as correct if that helps.


Regards,

Sumanth Meda

This doesn't seem to answer how to select a cart for a specific user.