onChange Catalog Client Script oldValue is empty

PabloL
Tera Contributor

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).

 

PabloL_0-1673023277742.png

PabloL_0-1673024258257.png

 

 

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.

1 ACCEPTED SOLUTION

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.

 

-Anurag

View solution in original post

4 REPLIES 4

Anurag Tripathi
Mega Patron
Mega Patron

Hi,

Old value will not work in this case.

When it is a record on a table (not a catalog) and the record is loaded. At that tie the old value of the field is set (it is the value that comes from DB). Now if you change it 10 times without saving the form, the old value will not change but new value will change each time.

Hope that helps explains what the issue is why Old Value will not work for you.

 

-Anurag

PabloL
Tera Contributor

Thank you for your feedback Anurag. How could I grab the previous value of the Choice in this situation?

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.

 

-Anurag

PabloL
Tera Contributor

Thank you Anurag! I ended up working around the problem like you mentioned. Happy New Year 2023!