Copy variable 1(Reference) value to the other variable 2(list collector) on change of the variable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2023 12:41 AM - edited 07-04-2023 12:42 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2023 03:42 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2023 04:10 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2023 04:41 AM
Just use g_form.clearValue('variablename2') before using g_form.setValue(); function.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2023 05:05 AM - edited 07-04-2023 05:05 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2023 05:37 AM
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 ?