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

Hello @Mehta ,

PFB code.

var watch = g_form.getValue('watch_list');
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('watch_list');
g_form.setValue('watch_list',application);
}

 

This is the piece of code used in the catalog client script.

I could see it's working for the first time but if we update second time without saving the record it's appending to the list.

Are you using catalog client script ? i am thinking of a value to store an value as old so we can remove it from the array.

yes I'm thinking of same and tried with some scripts but unable to make it if you could please provide some sample piece of code it would really help

You can create an extra variable which will be hidden all the time, and can utilize it to store the value of requested for or user and below is the script you can use to counter the issue.

 

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