is there a way to automatically clear the cart when an order guide is first opened?

patricklatella
Mega Sage

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!

1 ACCEPTED SOLUTION

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;


  }


});


View solution in original post

20 REPLIES 20

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;


  }


});


Hi, I would like to try this solution for the same issue. What table should be used for the onLoad client script?

Thanks in advance!

 

Cinthya.

patricklatella
Mega Sage

yep worked as a non roled user too.   thanks again!


patricklatella
Mega Sage

dan.bruhn   can you please mark Ajit's last reply as correct.



Still seeing the same issue, but I've traced it to when I have to use the "ask a question" button to the right, and if then if I don't mark the discussion as a question, then I can't see the "Correct Answer" option.



Still this is happening because the main "Ask A question" on the home page just freezes.   anyway, thanks!


I've gone ahead and marked Ajit's reply as correct.  



We did identify the issue you faced on the homepage and made the update.   Can you please try clearing your cache and closing out the browsers?   If that doesn't work let me know.



Thanks,