How do I refer to variables in variable sets in a client script?

gtke
Tera Contributor

I have a variable which is the only variable in a variable set. I am trying to modify this variable using a client script (g_form.setValue()) but it isn't working. I have another variable which is not in a variable set and that one can be set through g_form.setValue() in a client script. Currently I am referring to the variable in the set like this: g_form.setValue('<variable>','<value>','<display>') but I have also tried g_form.setValue('<variable set>.<variable>','<value>','<display>') and g_form.setValue('variables.<variable>','<value>','<display>') but none of these works. What is the proper syntax for this reference?

13 REPLIES 13

gtke
Tera Contributor

Single Line Text. I have tried it with other types, none seem to work using the g_form.setValue() method. We have another example on our instance where this method does work on a yes/no variable (not in a set).


g_form.setValue('variablename', 'texthere');


mmm2015
Kilo Explorer

I had similar problem on setValue. I had a variable directly under Service Catalog Variables. tried to set value on onLoad script.


Contacted Hi, that's when they said setValue works only with onChange script. It doesn't work with onLoad or onSubmit.


I have a variable set (requested_for_set) using a variable name of requested_for.



I am trying to get the location field to autofill on the Task at the time it is submitted, loaded or changed.


Nothing works! Have been searching SN and Google for multiple weeks. Many solutions outdated.
My test instance is Istanbul, while our dev system and prod are Helsinki.




function onChange(control, oldValue, newValue, isLoading) {


    if (isLoading)


          return;



    if (newValue == '') {


          g_form.setValue('location', '');


          return;


    }



    if (!g_form.getControl('location'))


          return;



    var reqLocation = g_form.getReference('requested_for');


            g_form.setValue('location', reqLocation.location);