- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2017 01:51 PM
I'm looking for a way to have an automatic cache out and empty of the cart when an order guide is opened to eliminate the possibility of old or "unchecked out" items being in the cart when the "checkout" page within the Order Guide is reached.
is this possible? thanks!
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2017 04:33 PM
Patrick, here you go. please mark as correct. also, check impersonating a user with no role.
onLoad client script:
function onLoad() {
//Type appropriate comment here, and begin script below
var ga = new GlideAjax('CartUtil');
ga.addParam('sysparm_name', 'clearCart');
ga.getXMLWait();
}
script include:
var CartUtil = Class.create();
CartUtil.prototype = Object.extendsObject(AbstractAjaxProcessor, {
clearCart: function() {
var clear = new GlideRecord('sc_cart_item');
clear.addQuery('cart.user', gs.getUserID());
clear.addQuery('active', 'true');
clear.query();
clear.deleteMultiple();
return;
}
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2017 01:15 PM
so with the box checked the cart above was my first order guide getting to the "Checkout" page. Then if I navigate away without submitting (which a user might do), then when I open the order guide again the next time, the items from the first cart are still there.
we are not using the 2 step check out model. Is that necessary to get this to work? We use a custom app store instead of the shopping cart. So we just need the cart to empty when the order guide is opened because of this one scenario.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2017 01:23 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2017 01:43 PM
from that other thread, I've pulled a couple things...definitely not working, but wonder if a simple edit is all that's needed? With this client script and script include the cart clears, but not til after the user moved to "Choose Options", so you get this. Need it to clear when the "Describe Needs" page first loads so that when the user moves to the "Choose Options" page ONLY the new items from the current order guide are there. See my scripts below...see anything? thanks
client script:
function onLoad() {
//Type appropriate comment here, and begin script below
var ga = new GlideAjax('CartUtil');
ga.addParam('sysparm_name', 'clearCart');
ga.getXMLWait();
}
script include:
var CartUtil = Class.create();
CartUtil.prototype = Object.extendsObject(AbstractAjaxProcessor, {
clearCart: function() {
var cart = new GlideappCart();
cart.get(null, gs.getUserID()).empty();
return;
}
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2017 01:57 PM
try this in your script include. there may be a better way which i dont knw.
var clear = new GlideRecord('sc_cart_item');
clear.addQuery('cart.user', gs.getUserID());
clear.addQuery('active', 'true');
clear.query();
clear.deleteMultiple();
}
return;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2017 03:10 PM
excellent Ajit, thanks works! here are my final scripts: (copy and paste this into one more reply from you and I'll mark your reply as the correct answer). thanks!
onLoad client script:
function onLoad() {
//Type appropriate comment here, and begin script below
var ga = new GlideAjax('CartUtil');
ga.addParam('sysparm_name', 'clearCart');
ga.getXMLWait();
}
script include:
var clear = new GlideRecord('sc_cart_item');
clear.addQuery('cart.user', gs.getUserID());
clear.addQuery('active', 'true');
clear.query();
while(clear.next()){
clear.deleteRecord();
}