How can we disable and enable fields on a X++ form Dynamics AX ?
Field1 is an enum with option option1 and option2.
We have below scenarios:
If Field1 is option1 then Field2 field should be enabled and Field3 field should be disabled/readonly
If Field1 is option2 then Field3 field should be enabled and Field2 should be disabled/readonly
3/ Also, when the form loads, for the existing records the Field3 and Field2 fields should be enabled/readonly based on their current value for Field1

You can override method
active()on the form's datasource, something likeThat's good enough if
Field1value cannot be modifed by the user. If it can be modified then it makes sense to create a new method e.g.setFieldAccess()with the logic similar to the above, and call this new method both from the datasourceactive()method and from themodified()method of the datasource fieldField1.