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

patricklatella
Mega Sage

and to refresh...I am looking for a way to have the cart contents clear when a new order guide is opened.   We don't use the cart for any other purpose, and as I detailed earlier in the thread, I need the cart to clear when my "New Hire" order guide is first entered so that there is no chance of overlap from previous and unfinished order guide entries.  


Patrick,



The simplest solution i can suggest is, there is a property in Service Catalog which allows clearing of cart when Order Now is clicked. see if this helps.



find_real_file.png


patricklatella
Mega Sage

Hi Ajit,


I checked set that system propery to TRUE and the cart still keeps old items from previous order guides...so it didn't work.   Wonder if that's because the items that were already in the cart were from the same order guide I'm using to test this.   We don't use the cart for anything other than 1 order guide that we're using.  


do u hv 2-step checkout? i tested this, if you hv this property set to TRUE, when you click Order Now, only the present Item will appear in Checkout page. the rest items are still in cart but does not appear at checkout. when you Proceed to Checkout the entire cart will show up.



Are you saying your company does not use cart feature at all and you want to do away with it?


patricklatella
Mega Sage

this is a thread I found, but since it doesn't have "Answered" checked and there seem to be issues with some of the suggestions I wasn't sure if I should follow it.