Currency field onLoad script not working for setDisplay and setVisible functions

gokulrovj
Giga Contributor

Hello,
I'm trying to hide out of the box Currency field using this code shown below but it's still visible despite being set to False. It's working for Disabled functionality. Please assist on this if it's a platform issue or if there is any alternative code for this.

g_form.setDisplay("u_rov_annual_budget",true);
g_form.setVisible("u_rov_annual_budget",true);

gokulrovj_1-1794137956110.png

 

Also, it works fine on  onChange script

 



Regards,
Gokul

Rafael Batistot
Mega Patron

Hi @gokulrovj 

 

Change true to false:

 

g_form.setDisplay("u_rov_annual_budget", false);

 

I recommend to use a UI Policy instead of a Client Script. Set the field's Visible policy action to False

 

Sreeram Nair
Kilo Sage

Hi @gokulrovj 

 

@Rafael Batistot is right that true needs to be false to hide the field. But since you mentioned it still shows with false, and the same code works in onChange, it sounds like something is overriding your onLoad script rather than a problem with the code itself.

 

A few things to check:

  1. UI Policies on the table. UI Policies run after onLoad client scripts, so a policy that sets u_rov_annual_budget to visible will undo your script. This would also explain why onChange works, because it runs later. Check for any UI Policy action on this field, including ones inherited from a parent table.
  2. Mandatory. setDisplay(false) won't hide a mandatory field that's empty. Check the dictionary entry and any UI Policies that make it mandatory.
  3. Script settings. Make sure the script is active, the UI Type is Desktop or All, and it isn't limited to a different view. Check the browser console for errors that might stop the script before this line runs.

The Field Watcher is the quickest way to find the cause. Right-click the field label, choose Watch, and reload the form. It shows every script and policy that touches the field, in order.

 

For the fix itself, I'd go with Rafael's suggestion: a UI Policy with a Visible = false action, and no client script. If another UI Policy is involved, use the Order field so the right one wins.

 

Also, use setDisplay rather than setVisible. setVisible(false) hides the field but leaves a blank gap in the layout.

gokulrovj_0-1794198811301.pnggokulrovj_1-1794198847341.png

Hello @Sreeram Nair @Rafael Batistot 
I have created the custom table not inherited from the parent table. I tried applying the UI Policy as shown in the screenshot. Even with that configuration, still the field is failing to hide when Rov Active field is false.

The policy settings in your screenshot look right. On load, Global and Reverse if false are all correct, and a new record's checkbox defaults to false, so the condition should match. That means something else is probably involved. A few things to check:

  1. UI Policy Action. Scroll to the UI Policy Actions related list and confirm there's an action for Rov Annual Budget with Visible set to False, not "Leave alone". Also confirm it points to the same field that's on the form. If a second field with the same label was created during testing, the action could be hiding the wrong one.
  2. Your earlier test scripts. Deactivate any client scripts you created while testing this, including the onChange one. onChange scripts also run when the form loads, so if the "if (isLoading) return;" line was removed, an old setDisplay(..., true) will run on load and override the policy.
  3. Mandatory. Check the dictionary entry for the field. A mandatory field won't hide while it's empty.

The quickest way to find the cause is the Field Watcher: right-click the Rov Annual Budget label, choose Watch, and reload the form. It lists every script and UI Policy that touches the field, in order, so you'll see exactly what is showing it again.

If none of these explain it, try a quick test: add a temporary string field to the form and give it the same UI Policy action. If the string field hides but the currency field doesn't, that points to something specific to currency fields. At that point it's worth checking Now Support for a known issue on your release.


If you can share a screenshot of the UI Policy Actions and the Field Watcher output, we can narrow it down further.