Automatically clear shopping Cart

Michael Nash2
Mega Expert

Hi Guys,

 

Is there a way to automatically clear the shopping cart after a certain period of time?

 

Thanks in advance,

1 ACCEPTED SOLUTION

Michael Nash2
Mega Expert

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());
}
}

 

 

View solution in original post

5 REPLIES 5

Angshuman3
Mega Guru

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

Just to be curious on which table, you will be using this client script?

Hi,

Use the Client Script on Shopping Cart Table.

Hope this helps.

Mark the answer as correct/helpful if you are satisfied.

Thanks,
Angshuman

Abhijeet14
Mega Expert

Hi


Use the above onLoad client script on shopping cart table

 



Mark correct if it is helpful.




Regards,
Abhijeet Bangera
 
www.dxsherpa.com