- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2023 11:45 AM
Hi,
We have a list collector and we need to be determine what item was removed from it in an onchange client script. So for example, if the list has 'A', 'B', 'C' in it and we remove 'A', leaving 'B' and 'C, we need to be able to know that 'A' was removed in the client script. I would have though comparing the oldValue and newValue parameters would work, however, the oldValue parameter is always returning a blank string / nothing regardless of what's added/removed in the list collector. Is there any other way to access the old value or determine what value was removed?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2023 05:39 AM
I understand better now. Previous values won't be accessible the way you want. However, you could have a hidden list collector that acts the way you want for the comparison. Example:
- List Collector A is displayed to the end user and is empty when the form is loaded
- List Collector B is hidden from the end user and is empty when the form is loaded
- List Collector A (current) changes and compares to List Collector B (previous)
- At the end of the comparison, List Collector B is updated to match List Collector A (new previous)
The script I provided would need to be updated to be something like this:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading/* || newValue === ''*/) {
return;
}
//Type appropriate comment here, and begin script below
var oldSplit = g_form.getValue('old_list_collector').split(',');
var newSplit = newValue.split(',');
var removedValue = [];
var addedValue = [];
for(var i = 0; i < oldSplit.length; i++) {
if(newSplit.indexOf(oldSplit[i]) == -1){
removedValue.push(oldSplit[i]);
}
}
for(var j = 0; j < newSplit.length; j++){
if(oldSplit.indexOf(newSplit[j]) == -1) {
addedValue.push(newSplit[j]);
}
}
var text = 'oldValue=' + oldValue + '\nnewValue=' + newValue + '\nremovedValue=' + removedValue.toString() + '\naddedValue=' + addedValue.toString();
g_form.setValue('u_text', text);
g_form.setValue('old_list_collector', newValue);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2023 05:50 AM
That seems to be doing what I need, thanks again much appreciated.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2023 06:00 AM
You're very welcome! And THANK YOU for being my 50th answer marked as solved!!! I'm very glad I was able to help! 😁
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2023 01:56 PM
Do you really need it while the user is updating the form or when they finally save it? Reason I ask is I'm wondering if a Business Rule would be the better solution?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2023 01:11 AM
Thanks for your response.
We would need to know the live values before submitting the form - it gets a little more complicated. We have multiple multi-row variable sets. The variable sets themselves are dynamically shown/hidden based on what the user selects in the list collector, and the rows in the variable sets are also created based on what the user selects in the list collector. If the user removes an option from the list collector, I have the code in place to remove it from the correct variable set, but it's the bit before that I don't have - actually getting the option that was removed from the list collector. Again I thought I could just compare oldValue against newValue but didn't realise oldValue only holds the value from page load. Hope that makes sense