Copy variable 1(Reference) value to the other variable 2(list collector) on change of the variable

rajasekharteja
Tera Guru

Hello All,

 

I need to copy variable 1 ( reference) value to variable 2(watch list).

 

If user updates the variable 1 value then the value should get updated in the watch list field i.e.., the earlier value present in watch list variable should be removed and should be populated with the new value selected in the variable.

 

NOTE: Both variables are part of variable set.

 

Is creating 2 client scripts a better option or if there is any better approach please guide me on this.

 

Thanks,
Raj

15 REPLIES 15

var watch = g_form.getValue('variable_name2');
var array = watch.split(,); 
var application = '';
 for (var i = 0; i < array.length; i++) {
            if(array[i] != oldValue)
{
             application = array[i]+","+application ;
            application = application.substring(0);
}
application = application +","+newValue
           g_form.setValue('variable_name2',application);

        

this script is basically convert the watch list into array and then checking with old value and forming a new string with comma separated value which will be use to set the variable.  

 

Depending on your case you can even use clearValue now before setting the variable.

I updated the script provided here and added to On change catalog client script but here i could see the value selected is appending to the list instead of removing the existing value present in the variable 2(watchlist) when update happens to the first variable.

Just use g_form.clearValue('variablename2') before using g_form.setValue(); function.

No it's not clearing the value it's still doing the same i.e.., the value is appending to the list but we have to remove earlier mapped value from watch list and map new value present in variable 1.

var watch = g_form.getValue('variable_name2');
var array = watch.split(,); 
var application = '';
 for (var i = 0; i < array.length; i++) {
            if(array[i] != oldValue)
{
             application = array[i]+","+application ;
            application = application.substring(0);
}
application = application +","+newValue
          g_form.clearValue('variablename_2')
           g_form.setValue('variable_name2',application);

 

Is you script look like this ?