- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2018 05:02 PM
hi all,
I'm working on an onChange client script on the Problem table that I want to throw one field message if the field was empty before the change, and another message if the field was not empty when the change was made. Seems simple enough, but I'm finding the using script like
if (oldValue != ''){
//then do something herre
}
doesn't work. What is the use case for "oldValue" and "newValue"?
my script that is close, but not working is below. Anyone see what's wrong? Or have a better solution? thanks!
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading) {
return;
}
//when a value is entered the first time
var prevValue = jQuery(control).attr('data-old-value') || '';
// touching other form controls causes this to fire, so only respond when the newValue is valid
if (newValue && newValue.length){
if(prevValue.length == 0){
g_form.showFieldMsg('u_workaround', 'Please be sure to create Known Error Record after entering the Workaround.','info');
jQuery(control).attr('data-old-value', newValue);
return;
} else if (prevValue.length != 0){
g_form.showFieldMsg('u_workaround', 'Please be sure to update the Known Error Record after editing the Workaround.');
}
}
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2018 05:52 PM
Patrick,
OldValue is unknown on load so use below code:
if (g_scratchpad.u_input == '' && newValue !='')
alert('1');
if (g_scratchpad.u_input != '' && newValue !='')
alert('2');
This will work for sure.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2018 05:59 PM
I forgot to mention one thing
You need to create a display business rule
g_scratchpad.fieldname = current.fieldname
in my case fieldname is u_input.
g_scratchpad.u_input = current.u_input

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2018 05:56 PM
Hello,
After the change did you save the form and tried again?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2018 06:01 PM
I think empty value will only be taken in consideration when you save the form with empty value and try again.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2018 06:23 PM
Funny . . . you take out isLoading and it works fine.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2018 08:17 AM
thanks everyone for the help...and Shishir it didn't matter when the record had been saved with an empty field, still threw the wrong error.
Kunal's solution worked perfectly...thanks again guys!