Set maximum quantity limit based on cat item

Wayne Richmond
Tera Guru

I want to set the maximum quantity here:

find_real_file.png

..based on a custom field I've created on the Catalog Item:

find_real_file.png

Is there are way to do this? I thought an onLoad Catalog Client Script would allow me to set the options of the choice list, however I'm not sure how to manipulate the values on the table like this. 

At the very least, can I prevent the form being submitted if the selected quantity is more than the value in my custom field?

Thanks all

1 REPLY 1

Musab Rasheed
Tera Sage
Tera Sage

Hello @Wayne Richmond ,

Try this below code which is used to restrict user from selecting more than 5 as quantity and tweak accordingly.?

Code:

Try adding a client script and script include

Client Script:Cart Limit
Applies to Catalog Item
Type: OnSubmit
Applies on Catalog Item View: true

function onSubmit() {
if (cartLimit(g_user.userID) == false) {
alert("Only 5 items allowed in cart");
}
}

Script Include: CartLimit
Client Callable: true
Script:
function cartLimit(userID){
    var cart = new GlideRecord('sc_cart');
    cart.addQuery('user',userID);
    cart.query();
    if (cart.next()) {
        var cartItem = new GlideRecord('sc_cart_item');
        cartItem.addQuery('cart',cart.sys_id);
        cartItem.query();
        if (cartItem.getRowCount() == 5) {
            return false;
        }
    }
}
 
Mark my answer as correct or hit like based on impact.
Please hit like and mark my response as correct if that helps
Regards,
Musab