Is there any way we can clear the values of all variables in a Variable set ?

Community Alums
Not applicable

Looks like we can hide and unhide the entire VS but incase of removal of values from the underlying variables we have to setValue to indiv variables ?

Do we have a workaround ?

1 REPLY 1

kiara1
Tera Expert

Hi Deb,



I am not sure if there is anything by ServiceNow to clear values of all the variable in that particular variable set. But I think you can write script to do that. I am assuming you are using client script to hide/show variable set, so can add the following logic in the same script. Depending on the number of variables you can do this in 2 ways:


1) If you have few variables in that variable set, then either individually clear values or create an array of variable names in that variable set. Use that array in a for loop to clear the values.


var arry = [variable1, variable2]; //keep on adding the variable names in future


for(var i =0; i < arry.length; i++)


{


        g_form.clearValue(arry[i]);


}



2) In case there are many variables or if there is possibility to add more variables in future, then have a query on "item_option_new" and get all the variable names related to that variable set. Again have a loop to add variable names in the array and then use the same for loop to clear values. You have to use GlideAjax as are doing server side query.



Let me know if this works.