How to get Shopping Cart Quantity in Catalog client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2019 03:30 PM
Hi All,
I am trying to get the value of shopping cart Quantity on to a catalog client script.
Requirement: Prior to Checkout, I need to identify the quantity in the cart and compare with another field "Free items" on a different table in ServiceNow instance
Based on the result, If Quantity in Cart >Free items then the user should not able to Checkout. If Freeitems >Quantity in Cart user should be able to checkout.
I have written a Catalog Client script to retrieve the values from Cart and a Script include to compare.
In the Client Script used below script Quantity value from the Shopping Cart using :
ga.addParam('sysparm_quantity', $('quantity').value); (with GlideAjax)
Even tried just an alert to check i.e. alert("('quantity').value: " + $('quantity').value); in Service portal a Java Script Error in Browser Console Error is coming. Heard "$" is an unsupported method in Portal
Can someone help me how to get Quantity value so that I can call from my Client script and compare in my Script include with my "Free Items" field
Regards,
Manoj

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2019 03:44 PM
You may need to query the sc_cart_item table to get the quantity.
Please mark this response as correct or helpful if it assisted you with your question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2019 10:26 PM
use the below code to get the cart item quantity:
var cartId = new sn_sc.CartJS().getCartID();
var quantity =0;
var item = new GlideRecord('sc_cart_item');
item.addQuery('cart', cartId);
item.query();
while(item.next()){
quantity= quantity+ item.quantity;
}
gs.print(quantity);
-satheesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2019 09:29 AM
Asynchronous GlideAjax does not work in onSubmit client script. Is there a way to get the quantity value in onSubmit client script through Service Portal?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2019 10:31 PM
Hi,
the helps of below thread
How to get Shopping Cart Quantity in Catalog client script ?
var count = $('quantity').value;
if(count > 1){
var conMsg = confirm('');
if(conMsg == true){
//Your code;
}
else{
return false;
}
}