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

Bharath Padaki
ServiceNow Employee
ServiceNow Employee

Hi Patrick,



I am the Product Owner for Service Catalog. I was wondering what the business use case is behind the requirement? I can see other issues arising out of such an approach (read side effects). What if I had an item with a 100 fields on it, populated and saved in the cart for ordering at a later point. With this action, that item and any information in it would be lost. Right?



Hopefully, you can help me understand the use case so I can help find a good solution.


patricklatella
Mega Sage

Hi Bharath,


thanks for the reply.   This is specifically to be used for an order guide that will be used by managers to request a collection of catalog items associated with a new hire...this will be my organizations global process for handling a new hire.



The behavior I'm seeing (that I need to go away) is that if I open up my order guide, and then load up the guide and get to the "Checkout" page, but then for whatever reason leave that page to go elsewhere in ServiceNow (or simply close out), and so basically will have to start over (there is no way to save an order guide, correct?), then when I start the process over and get back to the "Checkout" page, all my previous items from the initial order guide are there.   This will be tedious to deal with and confusing to the users.  



Ideally I'd love to a way to provide a "Cancel" button on the checkout page (BEFORE) submitting the checkout. (this would empty the cart)



Or...ideally I'd love to a way to enable a user to save an order guide so that they can return later to finish...but it would need to be independent of anything else in the cart.



But either way, I need the cart to cache when the user begins a new order guide, and specifically this New Hire one I've created.



Does this make sense?


Hi Patrick,



What release are you folks on? Based on that I can tailor my response


patricklatella
Mega Sage

Hi Bharath,


sorry for the delay in getting back to you...but I'm definitely still hoping to find this solution.   We are on Helsinki.