how to pass variables in service catalog item to sn_sc.CartJS() in Scripted REST API?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-18-2020 09:28 AM
Hi,
How to pass the variables of service catalog item to sn_sc.CartJS() .actually I am trying to call the sn_sc.CartJS() API in Scripted REST API.
I have to pass the four variables namely user,location,created by, action type,
Regards,
Phalguna

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-18-2020 09:36 AM
use below sample code to call cart api with variables
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();
Regards,
Sachin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-18-2020 09:42 AM
Hi,
this script would help you
try from background
Ensure you give valid variable names and values
var cart = new sn_sc.CartJS();
var item =
{
'sysparm_id': '0d08837237153000158bbfc8bcbe5d02',
'sysparm_quantity': '1',
'variables':{
'user': 'Abel Tuter',
'location': 'Texas',
'created_by': 'abel.tuter',
'action_type': 'hello'
}};
var cartDetails = cart.addToCart(item);
gs.info(cartDetails);
var checkoutInfo = cart.checkoutCart();
gs.info(checkoutInfo);
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-18-2020 10:02 AM
Hi Ankur Thanks for your information,Actually I need to place order.is that checkoutCart same as place order?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-18-2020 10:12 AM
use below code for place order
https://hi.service-now.com/kb_view.do?sysparm_article=KB0714209
Regards,
Sachin