Limit adding items to "Add To Cart "

mcclain
Mega Contributor

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 ?

5 REPLIES 5

Shishir Srivast
Mega Sage

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;  


      }  


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.


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;


      }


Thanks Shishir, Which table i should write business rule? "sc_cart" or "sc_cart_item"?