- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-03-2024 01:01 PM - edited ‎01-03-2024 01:15 PM
Basically what the subject says, I need a way to see if a reference field is cleared (user just highlights and deletes the content). OnChange doesn't capture it even removing the newValue == '' default at the top of it. I'm guessing because it's technically not cleared and the value hasn't really changed. Is there a way around this? I'm aware I can do this in a Business Rule, but I really prefer not to.
Generic example of what I'm doing if needed:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading) {
return;
}
if(newValue == ''){
g_form.addErrorMessage('My Error Message');
g_form.setValue('ref_field', oldValue);
}
//Type appropriate comment here, and begin script below
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-04-2024 02:04 PM - edited ‎01-04-2024 02:04 PM
I figured out the issue. I was having a brain fart I guess. Just needed to check the inherited checkbox as where the script was running was on a child table. (facepalm)
Thanks everyone.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-03-2024 01:14 PM
Hi @Eric Woody
I think there is missing "}" with if condition and if there is no change means there is no data in newValue object and you don't need to set the variable with oldValue object.
add the alert(newValue) and check if there is some value.
-Thanks,
AshishKMishra
Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-03-2024 01:17 PM
That missing { was just me removing out any sensitive information, my code has it. I do an alert before the if statement and it never fires, like nothing has changed, even though I have cleared the field and clicked off of it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-03-2024 01:23 PM
can you share more details on this form and field name where you are applying this onChange client script. Just re-check if correct Field Name configured in client script
Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-03-2024 01:33 PM
Typically speaking an onchange client script (after you remove the default condition check for blank) will react to the field being blanked out as long as it actually had a value - meaning the user made a selection, or typed a value and actually exited the field. It won't fire on a string field, for example, if they type something but then delete it before they exit.
Try something like this and see what results you get.
Might go without saying, but make sure you have the correct field selected (that's caught me a few times).
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading ) {
return;
}
alert("New Value: " + newValue + " Old Value: " + oldValue + " type is: " + typeof(newValue));
}
Michael D. Jones
Proud member of the GlideFast Consulting Team!