Disabling a field when an enum is set to null.

Hi ,

I have a field named as ReferenceID and baseenum field ReferenceName which contains 3 values in it

ReferenceName can either be null , Teacher or student .

I want that when i choose null then the referenceid field should be disabled automatically.

My query is :

  1. where should i need to place my code for achieving this?

  2. If i set the refrenceId field to mandatory will by functionality work or will it throw error?

  3. what should be the appropriate code for this ?

  4. When do we write codes in modified field in form datasource ?

Don’t set the referenceId to mandatory, rather handle the situation in validateWrite. (if the value is other than null and if you don’t have any value in referenceId just throw an error in validateWrite). If this is specific to a form write it in form data source level or if the validation should happen from all the forms that use this data source then write it on the table)

You need to have the code for disabling the RefereneceId in both modified field and data source active.

Dynamics AX doesn’t support nullable value types, therefore you can’t set null to an enum field. You need an enum with three values (e.g. NotApplicable, Teacher and Student). Then use it as any other enum.

Because each enum field always have one of its values, setting it as mandatory doesn’t make sense. If you did it, you wouldn’t be able to save the record if you choose the enum element with value = 0.

Null i would take as NONE(that what he meant i believe) . I think he is not asking to set the enum field to mandatory rather another field based on the selected enum field value.

A value called None and a null value are two completely different things. It’s important to be aware of the difference.

You believe that the didn’t mean null when talking about null, but it seems plausible to me that he did mean null or he doesn’t understand the difference.

yes Null here is none , and now i changed the mandatory to ‘no’ and i am confused about the code placement as i know the code is to be written in modified field (but when in table and when in form) someone told me that i need to write in both (why is that so) why will it wont work when we write the code in only one.



Again, enum values and null are completely different things. You can’t use them interchangeably. Null represents the absence of value, not any value. If AX supported nullable enums, you could have a variable pointing to null (= no value) or pointing to a value such as None, which would clearly be two different things. But because AX doesn’t support nullable enums, saying that the value is null makes no sense.

I would expect your code to handle two situations:

  • When you activate a record without changing the value (in active())
  • When you change the value (in modified())

Null is the name and not the enum value

This is what i placed in the form>datasource>referencename>modifiedfield()

public void modified()


smylRefName smylRefName;

if (smylRefName::None)







But its not working , why ?

Could you be a bit more specific in describing your problem? “It’s not working” isn’t very specific.

Anyway, ,look at the if condition - it makes no sense:

if (smylRefName::None)

You forget to compare compare the None value with the current value of your field!

Get used to using the debugger - you would easily find it by yourself if you tried.

Also throw away the reread and refresh, it makes no sense there either. And remove smylRefName variable, because it’s not used. Your debugging will be easier as soon as you get rid of code that shouldn’t be there.