emptying the cart

Liam T
Tera Contributor

Hi guys,

I want to empty the cart in the self service which have not been checked out withing 7days adding to the cart.

As user the cart should be emptied if its not checked out within 7days.

 

Thank you.

1 ACCEPTED SOLUTION

Raghav Sharma24
Giga Patron

You need to write a scheduled job which runs everyday with below code:

 

var cart  = new GlideRecord('sc_cart_item');
cart.addEncodedQuery('sys_created_on<javascript&colon;gs.beginningOfLast7Days()');
cart.query();
while(cart.next())
{
cart.deleteRecord();
}

 

Note: All scripts should be tested in dev before executing in prod.

View solution in original post

3 REPLIES 3

Raghav Sharma24
Giga Patron

You need to write a scheduled job which runs everyday with below code:

 

var cart  = new GlideRecord('sc_cart_item');
cart.addEncodedQuery('sys_created_on<javascript&colon;gs.beginningOfLast7Days()');
cart.query();
while(cart.next())
{
cart.deleteRecord();
}

 

Note: All scripts should be tested in dev before executing in prod.

@Liam T Do mark the relevant answer correct if this resolves your issue.

Liam T
Tera Contributor

Hey Raghav,

Yeah I did some tweaks for the code you send and it worked

Thank you