Wednesday 6 February 2019

D365 Js Tips - Hide / Show / Enable / Disable a field - Best Practice Tip 1



Quick tip to avoid redundant code to enable/disable/show/hide a field. 

1. Hold the result of hide or disable condition in a variable.

Var isDisable =(formContext.getAttribute('accounttype').getValue()==1);
2. Use the result in disable rule so that it will flip between enable and disable without redundant script lines for enable/disable and avoids if branching

formContext.getControl("<Field Name>").setDisabled(isDisable);

3 comments: