Clear fields/variables when clicking on "Add to Cart"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-14-2010 03:40 AM
Users may want to order the same catalog item multiple times. Currently they need to fill out the information and click "add to cart" , then they have to go back to the service catalog to reorder the item. This simple modification will clear out the fields (reload the window) after they click "add to cart" so that they can put in multiple requests.
Out of the box, the car is contained in a UI Macro called 'catalog_cart_default'. When you press the 'Add to Cart' button, it triggers a function called 'addToCart' that is contained in the macro. All you need to do is add a single line (reloadWindow(window)); right before the closing bracket for that function.
Thanks Mark!
Sean
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-03-2016 04:31 AM
Hi Ben,
Thanks for this. We needed functionality that would apply only to specific items and this script does the job.
One amendment I did have to make to your script, which others may find useful, is that in the current version of ServiceNow I am using (Helsinki Patch 3) it appears the element ID add_to_cart_button has been changed to oi_add_to_cart_button.
So we have an onLoad script for catalog item that looks like this:
function onLoad() {
document.getElementById('oi_add_to_cart_button').addEventListener("click", function(){
reloadWindow(window);
});
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-15-2017 09:51 AM
I am trying to implement this on a specific item on Istanbul. This modified script in not working for me. Does anyone have a version of thew script that would work on Istanbul?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-08-2012 11:24 AM
You could make a copy of the default cart and then make the modifications as indicated above. Then if you want to change it to clear things out for the form you can just use the modified cart instead of the default.
There is a reference field for the "Cart" that is not included by default that you would need to add to the Catalog Item form. Once that is there you can just put in the newly modified cart to have it clear out the fields.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-12-2014 06:57 AM
Had to sign in to say THANKS for this -- helped us clear a hurdle with a request item we had

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-12-2014 08:01 AM
Thank you Sean for sharing the information