Dynamics 365: Add a new enum value

 In Development, Dynamics 365

Adding a new enum value requires creating an extension, as for any other modification over the Dynamix 365 for finance and operations standard.

The procedure

In the application explorer we can locate the enum that we want to extend. We will use NumberSeqModule in this example. Expanding the enum node shows the values it contains, as shown in the following image.

In order to extend an enumeration, it must have the IsExtensible property set to true. The following image shows our example is extensible.

As our example can be extended, just right click on its name and select Create extension. That will create the extension in our current project.

In the solution explorer we will then have the extension created. By default it has the name of the extended object followed by “.extension1” (or the corresponding number to avoid name collisions), which we can rename at will.

Double clicking on the extension node from theSolution Explorer opens the design view, where new values can be added. The next image shows the design view.

But, what are all those values? In the first image of this post there were far less values. When consulting or even when opening the design view of an enum, only the baseline values appear, but doing the same from the extension shows all the values of all the extensions (and the model they are in) that the enum has.

Right clicking on the name of the enumerated we can create new values and set the properties we want, like the name, the label or configuration key.

The details to keep in mind

In the procedure we have seen that the steps to create a new value in an enum are simple and that even if you do not see all the existing values at the beginning, at the moment of setting a name to the new value we will have at our disposal all the elements that exist in the application extensions, so that we can choose an unique and useful name for our value.

In previous versions, the numerical values of those enums were deterministic, so that, instead of making comparisons with the names, we might be tempted to compare against the numerical value. Falling into temptation complicates maintenance of our modifications and migrations between environments. Like with other changes in Dynamics 365, now we are forced to work with a cleaner metodology. Baseline numerical values remain deterministic (but are chosen by Microsoft and could change in a future release). The numeric values of the extensions are determined at runtime, so each time we work with the enum values their numeric value can be different.

Recommended Posts

Leave a Comment