- 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
‎07-24-2017 11:42 AM
I followed Brad's suggestions and it works for me.
Basically create a new script include called MyCart. Copy the entire SVN Cart code; but rename the class name to "MyCart". Also make the new script include a Global and accessible from All application scope.
After that I can call it from UI actions.
Cheers,
Henry