Best way to handle clearing values from hidden variables ?

johnnyw
Mega Expert

Hi,

I wanted to know what the best way to clear values from catalog item variables that are hidden.

Here is the scenario, I have a catalog item with several variables.   I also have UI Policies that make variables visible depending on the value selected in a different variable.   If I selected "Yes" in VAR1 to make the VAR2 visible, then entered a value in VAR2, but changed my mind and selected "No" in VAR1 to make VAR2 disappear again.   The VAR2 value is still stored and will write to the tables which will cause problems in my notifications since I am sending all variables values that are not null.

What is the best way to clear out the values from variables that are hidden?

Thanks,

Johnny

8 REPLIES 8

Sorry, I haven't found a solution for this.   It's been almost a year and I just searched on this topic again since I haven't implemented anything since my initial question.   I've created client scripts on specific catalog items that would clear specific variables if hidden, but I would like to see if there was a way to create a generic onSubmit client script that I can apply to any catalog item that would clear the values from all variables that are set to not visible via UI Policies.   That would accomplish what I need.   I am not clearing list collectors since I haven't used any in my catalog items.



UI Policies are easier to work with and maintain so I don't want to convert all of my UI Policies to Client Scripts.


Hi Johnny,


Did you get any solution? I have the same problem


I just run into the same question, to have a script usable for all, looping all variables.


Unfortunately the API does not offer a method to check isVisible or isDisplay.


I had a look into the OOTB g_from code, setDisplay/Visible just set the element style,


based on 2-3 conditions to locate the right element to change.


Based on this should be possible with some lines of code, may I'll try next days.


But in this way no guarantee that it works in future versions,


but worst case you need the adapt the script again.


Hopefully one day the API becomes such methods.


Cristian95
Tera Contributor

Hello!

 

I had the same problem and found the following explanation, hope it helps 🙂

 

https://www.servicenow.com/community/developer-articles/clear-the-field-value-clear-the-variable-val...

 

Cheers!