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 05:47 AM - edited 07-05-2023 07:29 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2023 05:54 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2023 09:47 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2023 11:14 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2023 12:50 AM
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);
}