Need a script to validate the current catalog item is already in the cart list

swetha53
Kilo Contributor

I have   selected a catalog item and clicked on "Add to cart" twice. catalog item was added twice to the request.In order to avoid this i need to validate on   click on                     "add to cart item" this should throw a pop-up like "Catalog item is already selected do you want to continue?"

24 REPLIES 24

You can just add an onSubmit client script to your Catalog Item - so it would be a Catalog Client Script. It could even be part of a variable set, for that matter.


Just make sure to call the checkCart function from within your onSubmit function - or just paste the contents of the checkCart function into your CS.


This worked as I would like when Add to Cart is clicked but when Order Now is clicked, it adds the item on the screen to the cart and orders it.   I need to have it prompt for Order Now as well.


Can you paste your client-side code? You need to make sure you return false if you don't want the form to submit.


function onSubmit() {


checkCart() ;

function checkCart() {
//alert('inside function');


  var catItem = gel("sysparm_id").value;


  var cart = new GlideAjax('CheckCart');


  cart.addParam('sysparm_name', 'checkCart');


cart.addParam('sysparm_catItem', catItem);


  cart.getXMLWait();


  var resp = cart.getAnswer();


  if (resp) {


// prompt user with confirm()


}


// Otherwise, allow submission.


  return true;


}
}