Need a script to validate the current catalog item is already in the cart list
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2015 08:20 AM
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?"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2016 07:55 AM
Try this
Previously, I just had a comment snippet in there instructing you what to code in that place. This script is updated with the actual code.
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()
confirm('This item already exists in your cart - would you like to order another?');
}
// Otherwise, allow submission.
return true;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2016 07:55 AM
that should be:
return confirm('This item already exists in your cart - would you like to order another?');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2016 08:14 AM
Sorry - I did it quick and didn't put my own comment in there 🙂 Very close but this time I get the comment even if there isn't already an item in the cart - i get it on ordernow and add to cart before I have one item there.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2016 08:29 AM
What value are you getting back from the script include? Can you print your resp variable? I wrote all of that really quickly as an example, so this will just confirm that it's working. Go ahead and
alert(resp);
on the line before the confirm.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2016 09:31 AM
Returns false