- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2018 02:21 AM
Hi Guys,
Is there a way to automatically clear the shopping cart after a certain period of time?
Thanks in advance,
Solved! Go to Solution.
- Labels:
-
Service Catalog
-
Service Portal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2018 10:24 PM
Thanks Guys,
You pointed me in the right direction.
I was able to resolve this myself by creating a scheduled job with the below script.
expiredCartItem();
function expiredCartItem() {
var cartItem = new GlideRecord('sc_cart_item');
cartItem.addEncodedQuery('sys_created_onRELATIVELE@dayofweek@ago@3'); //delete item from cart if created more than 3 days ago
cartItem.query();
while(cartItem.next()) {
cartItem.deleteRecord();
gs.log(cartItem.cat_item.getDisplayValue() + " expired and removed from users cart: " + cartItem.cart.user.getDisplayValue());
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2018 02:44 AM
Hi Michael,
Try This...!!
onLoad client script:
function onLoad() {
var gr = new GlideAjax('CartUtil');
gr.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;
}
});
I had used this one to clear the cart from the existing items which were already present in the Cart. Check if this works..!!
Hope this helps.
Mark the answer as correct/helpful if you are satisfied.
Thanks,
Angshuman

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2018 04:05 AM
Just to be curious on which table, you will be using this client script?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2018 09:37 PM
Hi,
Use the Client Script on Shopping Cart Table.
Hope this helps.
Mark the answer as correct/helpful if you are satisfied.
Thanks,
Angshuman

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2018 04:59 AM
Hi
Use the above onLoad client script on shopping cart table
Mark correct if it is helpful.
Regards,
Abhijeet Bangera
www.dxsherpa.com