- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-06-2023 08:42 AM - edited 01-06-2023 08:57 AM
Hi Community! Happy New Year!
I wrote an onChange catalog client script on a Variable named "Pickup Choice". This variable is type "Select Box" and has a choice list with choices like "Pickup" and "Ship to my Location".
The purpose of this script is to clear the mandatory status of the comments variable, which is made mandatory by a UI Action before the pickup choice is changed.
My issue that I found is that I tried to make the client script run only when oldValue == "Ship to my location" to signify the user selecting a different choice. However, I noticed that when I selected a new option, the oldValue was empty (but the newValue was correctly populated with the new choice).
Why could I not have access to oldValue? I'm trying to do this from the Platform UI with UI16 on a simple Catalog Item.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-06-2023 09:10 AM
You might have to be sneaky with it. There is no direct way I'm afraid.
Create another variable that is not visible to the user ever and populate the value user selects each time in the field in question and set it in the hidden variable, read it from there when you need.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
As a workaround, I cache the last known value in sessionStorage and treat that as the “previous value” on subsequent onChange events:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
sessionStorage.clear()
return;
}
var oldItemValue = sessionStorage.getItem('item');
sessionStorage.setItem('item', newValue);
if (oldItemValue) {
// code here...
} else {
// code here...
}
}
