Resetting/Emptying variable values onSubmit

nomadie
Kilo Expert

I need to do multiple request/order of the same catalog form, using Add to Cart and I need to clear these two fields everytime I click on the add to cart button.

Catalog Client Script doesn't work clearing/resetting/emptying the variables because it affects the RITM/SCtask form too... Would you know other way to fix this? I only need to clear 2 fields out of 5 variables/questions. 

Catalog Client Script
Type: onSubmit
Applies on a Catalog Item view: True
Applies on Requested Items: False
Applies on Catalog Tasks: False
UI Type: All

function onSubmit() {
   //Type appropriate comment here, and begin script below
   g_form.clearValue('install_software');
   g_form.setValue('new_hire_software_justification','');
}
11 REPLIES 11

Anil Shewale
Mega Guru

Hi nomadie

try with ui policy.

choose your field and there is option Clear the field value . check it

see in below fig.

If it help mark helpful or correct 

Thanks and regards

Anil

 

UI Policy wont do the work as well. I already tested this.

Onkar Pandav
Tera Guru

Hi,

Give it a try. Please check below link.

https://community.servicenow.com/community?id=community_question&sys_id=186d47e9db9cdbc01dcaf3231f96...

Out of the box, the cart 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.

Let me know if it is useful.

No, I cannot use this option because it will reload the whole page. I need to retain previously entered information. I only need to clear specific variables/questions.

DrewW
Mega Sage
Mega Sage

Sounds like you just need to set the catalog client script to only apply on the Catalog Item view.