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

srinivasthelu
Tera Guru

Hi Jhony,



The easiest way would be modify the same UI Policy to Run Scripts



Screen Shot 2016-02-12 at 10.54.44 AM.png




Thanks


Srini


Thanks Srini.



Is there a way that a script can be created to generically clear the values of any variable that is hidden without having to specifically call out the variable name?



I'm not a javascript programmer, so my knowledge is rather limited.



Regards,


Johnny


Hi Johny,



You can start with below link on how to set or clear values via script.


GlideForm (g form) - ServiceNow Wiki



I will get back to you in case I found any easy way for this req.


kristenankeny
Tera Guru

Were you ever able to find a way to script this? Right now, my client scripts are so messy because every time i hide a variable, I'm having to specifically clear its value. Also, were you having to clear list collectors as well? I'm trying to figure out how to identify the type of variable so I can either us clearValue or a script I found on servicenowguru to move the selections to the left bucket when a list collector.