Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Clear the form when add to cart

rp1
Tera Expert

I'm attempting to clear a form when the user clicks "Add to Cart".

 

I found this

https://www.servicenow.com/community/developer-forum/clear-variables-on-form-when-quot-add-to-cart-q...

 

Which lead to this

https://www.servicenow.com/community/service-management-forum/need-to-clear-all-variable-value-once-...

 

I attempted to put the following code in a Client Script with no luck.  Any advice on how to get this to work?

function onLoad(){
	
	document.getElementById('add_to_cart_button').addEventListener("click", function(){
		reloadWindow(window);
		});  

}  
2 REPLIES 2

Shruti D
Kilo Sage

Hello @rp1 

Try with the below Script:

function onLoad() {
  document.getElementById('add_to_cart_button').addEventListener("click", function() {
    // Reload the window
    location.reload(true);
  });
}

window.addEventListener('load', onLoad);

 

 

 

 

 

Please Mark Correct  ✔️ if this solves your query and also mark Helpful 👍 if you find my response worthy based on the impact.

Regards,
Shruti

Still not working.  I'm opening a developer instance on the off chance it's something with our instance that is preventing the code from working.

 

edit - doesn't work in developer instance either....  
Console displays the following error -

running Client Script "Clear Form": TypeError: Cannot read properties of null (reading 'addEventListener')

   which makes sense because it's null on load because nothing has been done yet.