Limit adding items to "Add To Cart "
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-28-2017 02:22 AM
Q3. We have a requirement to limit no of catalog items added to cart to 5 not more than that. If user has to add new item. first they should clear the 5 items in their cart. Any suggestions ?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-28-2017 03:31 AM
Hi McClain,
I think this can be achieved using Business Rule. Please check.
var id = gs.getUserName();
var count = 0;
var gr = new GlideRecord('sc_cart_item');
gr.addQuery('cart.sys_created_by', id);
gr.orderByDesc('sys_created_on');
gr.query();
while(gr.next()) {
if(count > 5) {
alert('Catalog item can not be more than five');
}
++count;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-28-2017 09:07 AM
Hi Shirshir,
If it is business rules i don't think alert() will work in Business rule(Server side), alert will work only in client side.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-28-2017 09:17 AM
That's absolutely correct Balaji . alert() will not work on Business Rule. Please have a Small correction in below script.
var id = gs.getUserName();
var count = 0;
var gr = new GlideRecord('sc_cart_item');
gr.addQuery('cart.sys_created_by', id);
gr.orderByDesc('sys_created_on');
gr.query();
while(gr.next()) {
if(count > 5) {
gs.addInfoMessage('Catalog item can not be more than five');
current.setAbortAction(true);
}
++count;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-30-2017 04:31 AM
Thanks Shishir, Which table i should write business rule? "sc_cart" or "sc_cart_item"?