- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-17-2024 10:17 AM
I am working on a custom solution for my customer. On a form, when users make selections in a reference list field, we have specific fields that we want to appear. Some of the fields grab values from the referenced table and some are blank, allowing the user to input their own value. If the user removes a selection, we want the field to disappear AND clear any value that was there. There are calculations that run and we don't want those hidden values to be calculated.
I have successfully achieved this with client scripts, however, the last field remains displayed on the form after it is deselected. Saving is required to remove the form but even after saving, the value remains as evident by running the calculations and seeing that the numbers displayed in the input fields do not add up to the final value. No matter what the last field is, if it is last, it stays.
Can any assistance be provided in figuring out how to get this last field to operate as intended?
I have tried using a loop although I am not confident my ability to accurately script that. I have also tried the if statement you see at the very bottom of the script provided so that if "newValue" does not contain any sys_id's, then setDisplay "fields" false and clearValues for all "fields".
Thanks in advance.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-17-2024 10:25 AM - edited ‎07-17-2024 10:26 AM
Replace the below code:
if (newValue.indexOf('')) {
g_form.setDislay(fields, false);
g_form.clearValue(fields);
}
with:
if (newValue == '')) {
for(var i=0; i<fields.length; i++)
{
g_form.setDisplay(fields[i], false);
g_form.clearValue(fields[i]);
}
}
Just remember that you need to update at the beginning of the client script to run it even when newValue is empty... like this:
if (isLoading) { //Run even if new Value is empty
return;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-17-2024 10:18 AM
I should add that this is an onChange client script set to monitor the list field.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-17-2024 10:25 AM - edited ‎07-17-2024 10:26 AM
Replace the below code:
if (newValue.indexOf('')) {
g_form.setDislay(fields, false);
g_form.clearValue(fields);
}
with:
if (newValue == '')) {
for(var i=0; i<fields.length; i++)
{
g_form.setDisplay(fields[i], false);
g_form.clearValue(fields[i]);
}
}
Just remember that you need to update at the beginning of the client script to run it even when newValue is empty... like this:
if (isLoading) { //Run even if new Value is empty
return;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-17-2024 10:50 AM
It looks like the corrections to the isLoading at the beginning of he script resolved the issue. Thank you very much for your assistance!