Requirement to add an order guide to a manager's cart
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2023 08:19 AM
I need to use the Cart API to put an item in a manager's cart before the new employee starts:
var cart = new sn_sc.CartJS();
var item =
{
'sysparm_id': '6c07f44fdb70a70020c06c16ca9619f7',
'sysparm_quantity': '1',
};
cart.setRequestedFor("940ec417db2aa450f0659605f39619ef");
var userId = cart.getRequestedFor();
gs.info(userId);
var cartDetails = cart.addToCart(item);
gs.info(JSON.stringify(cartDetails));
I looked at the cart API and changed the cart.setRequestFor to the manager's sysid but the items keep getting added to my cart. I need a way to access the other user's cart.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2023 11:14 PM
Hi @prithaMajumdar ,
Make sure to add correct sys_id of manager the script looks good.
var cart = new sn_sc.CartJS();
var item = {
'sysparm_id': '6c07f44fdb70a70020c06c16ca9619f7',
'sysparm_quantity': '1'
};
cart.setRequestedFor('manager_sys_id');
var cartDetails = cart.addToCart(item);
gs.info(JSON.stringify(cartDetails));
Thanks,
Anand
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2023 01:18 AM
Hi Anand,
It is correct sys_id, I am running this as background but the item is getting added to my cart. not the manager's...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2024 10:14 PM
When i add item through this script and retrieve from cart in portal is not showing next button in order guide. Also how to set order guide variables through this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2023 04:12 AM
Wrote my own code to fix this:
// Create a new GlideRecord object for the sc_cart table
var cartRecord = new GlideRecord('sc_cart');
var cardId = '';
// Set values for the fields
cartRecord.addQuery('user', '940ec417db2aa450f0659605f39619ef'); // Replace 'user_sys_id_here' with the actual user's sys_id
cartRecord.query();
if(cartRecord.next()){
cardId = cartRecord.sys_id.toString();
}
var cartItm = new GlideRecord('sc_cart_item');
cartItm.initialize();
cartItm.cat_item = '1462a49087c2f9106bfe657f8bbb35dc';
cartItm.cart = cardId;
var newItm = cartItm.insert();
gs.log(newItm);