Client script oldValue always empty

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2017 12:12 PM
I am writing an on Change script for the change module. When I try and if (newValue == 'This' && oldValue == 'that') it is not working. So I did a alert(newValue) along with an alert(oldValue) and oldValue is away returning as empty. What might be causing oldValue not to return anything? Just note that newValue is always returning what I expect it to.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-18-2018 03:27 PM
Hi Brian,
Sorry it was a long thread and didn't read through all. Apologies if i am stating what is already established here.
Old Value comes from the Database when the form is loaded, unless the firm is saved again the old value will not change. So on a new record, unless you save it the old value will always return null.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2025 05:48 AM
If you come across this post here is the answer as of March 2024.
You need to leverage sessionStorage functions on the client side. See the universal documention covering sessionStorage.
What you need to do is have a client script that onChange to store the field value using
sessionStorage.setItem("key", newValue);
Then when you want to see the "old" value - which was set prior using the above
var data = sessionStorage.getItem("key");
It basically boils down to you are keeping a secondary copy of the value in the session to extract later.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2025 08:10 AM
I just tried testing this out. It is not consistent. It only seems to work the first time you change the value. I did have to modify the first line you gave otherwise it never worked.
sessionStorage.setItem("key", oldValue);
I don't even 100% remember why I was trying to even to this. I have not tried to use oldValue in a client script since this initial post.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2025 06:18 AM - edited 05-16-2025 06:18 AM
Hi @Brian Lancaster
What I understood, your requirement was get old and new value in every change. Can you try below code
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === oldValue) {
return;
}
// Initialize the previous value variable if undefined
if (g_form._previousValue === undefined) {
g_form._previousValue = '';
}
alert('Old Value: ' + g_form._previousValue + '\nNew Value: ' + newValue);
// Update the stored old value for next change
g_form._previousValue = newValue;
}
Regards,
Akshay Kangankar