- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-06-2019 07:45 AM
Hey guys,
I'm working on a client script that clearValue()'s fields below a given field on a form. I'm using an onChange script but have an edge case thats giving me some unexpected behavior. The targeted field is a reference field, but if the user manually clear's the field the onChange script does not run. If the field is then given value either through a reference or user input the onChange script runs as expected. The primary issue here is that a user can accidentally clear the field, then put the original value of the field back but sub fields get cleared even though technically the field "hasn't" changed.
Is there any way to check if the reference field has been cleared by the user?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-06-2019 07:50 AM
The default script contains a line that checks for newVal == ''" and if so exit the script. You can remove that from if statement in the script and it will run whatever code you have.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-06-2019 07:50 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-06-2019 07:53 AM
Hi Derek,
when you use clearValue() it doesn't trigger the onChange script
try removing newValue === '' in the function
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
change this to below
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading) {
return;
}
Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader