- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-30-2017 11:18 AM
Is it possible to use Cart API in UI Actions?
The following code not working (Cart undefined). What my other options to order a catalog item in UI Actions?
=========
var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
var item = cart.addItem('e46305bdc0a8010a00645e608031eb0f');
cart.setVariable(item, 'os', 'Linux Red Hat');
var rc = cart.placeOrder();
gs.addInfoMessage(rc.number);
========
Thanks,
Henry
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-31-2017 06:33 AM
No it definitely won't work if it runs client side. If it happens in the scoped app I think that's the issue. The Cart script include is not available from a scoped app by default, so you have a couple of options. The first involves updating the OOB cart script include and making it available from all application scopes, but I don't think that's a great idea.
ServiceNow Cart API in Scoped Application
I think what I would do is just copy the Cart script include and create a new one in your scoped app that it can use.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-30-2017 04:12 PM
I would make sure that you don't have the client checkbox checked so your ui action runs server side. Also, does this happened to be part of a scoped app?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-31-2017 06:28 AM
Thanks Brad,
Good point.
No, I did not have the client checkbox checked. And yes, it happens in a scoped app.
I will enable the 'client' option for this UI action. I also need a scheduled script execution to do the same thing (i.e. place an order to the cart to trigger the workflow). How can I achieve this on the server side?
Thanks,
Henry

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-31-2017 06:33 AM
No it definitely won't work if it runs client side. If it happens in the scoped app I think that's the issue. The Cart script include is not available from a scoped app by default, so you have a couple of options. The first involves updating the OOB cart script include and making it available from all application scopes, but I don't think that's a great idea.
ServiceNow Cart API in Scoped Application
I think what I would do is just copy the Cart script include and create a new one in your scoped app that it can use.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-11-2017 04:22 AM
Hi Brad,
I have the same scenario. In my case the UI action is list choice type. So, to fetch the selected values I have made it client callable. But, as you have said Cart API wont work in this scenario.
Is there any way out? Kindly help.