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

RaghavSh
Kilo 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.


Raghav
MVP 2023
LinkedIn

View solution in original post

3 REPLIES 3

RaghavSh
Kilo 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.


Raghav
MVP 2023
LinkedIn

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


Raghav
MVP 2023
LinkedIn

Liam T
Tera Contributor

Hey Raghav,

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

Thank you