How to do it...

In order to create a new Enum, follow these steps:

  1. Either right-click on the project (or any subfolder in the project) and choose Add | New item....
Always try to use keyboard shortcuts, which are displayed next to the option. In this case, try Ctrl + Shift + A.
  1. This will open the Add New Item window. On the left-hand list, select Data Types, which is under the Operations Artifacts node.
  2. This will filter the available options on the right-hand list. From this list, choose Base Enum.
  3. Enter a name, prefixed appropriately. In this example, we are creating an Enum to store the type of vehicle; so, we will enter ConWHSVehicleType as Name and press Add.
This should have created a folder called Base Enums, or added the new Enum to the folder if it already existed. This is regardless of the folder we selected when the Enum was created. If this did not happen, the Organize projects by element type setting in Dynamics 365 | Options was not checked.
  1. We will now have a new tab open with our empty Enum. Before we continue, we must create labels for the Label and Help properties. Double-click on the label file so we can add a new label.
This was created in the previous chapter; if you don't have a label file, one must be created before we continue.
  1. This will add an empty line for us. On this empty line, click on Label ID and enter the next number, for example, 1, and press Tab. This will change the number so that it is prefixed with the label file ID; in our case, ConWHS1.
  2. Enter Vehicle type in the Label column and ConWHS in the comment: this is to provide context to other developers, in case it is reused.
  1. Press New and repeat for the next label and enter the text The type of the vehicle for the Label property.
Repeat these for each label file language we created; if we support US and British English and Norwegian Bokmål, we will need to create a label with the same ID for ConWHS.en-us.label.txt, ConWHS.en-gb.label.txt, and ConWHS.no-no.label.txt.
  1. Reselect the tab for the Enum. If we don't have a property sheet open, which is usually on the lower right of the screen, right-click on the Enum inside the tab and select Properties.
  2. In the property sheet, fill in the Label property as Vehicle type.
  3. Press the lookup button for this property, select our label, and press Paste label.
  4. Repeat this process for the Help property, which should be The type of vehicle.
These properties do not have to be populated, but it will cause a best practice deviation warning when the project is built and these properties are left empty.
  1. The Use Enum Value property should always be Yes, as it allows us to set the numeric value of each symbol we created.
  2. The Is Extensible property should usually be False. This alters the way the numeric value is assigned, and is described later.
  3. Next, we will add the elements to the Enum. There must always be an element with 0, as this is the default on new records. Also consider that having a default is desirable. If you wish to force the user to select an option, make the first element "Undefined". Since 0 is classed as empty by the system, making the field mandatory will force the user to select an option. The options we will add should be created as follows:

Name (Symbol)

Enum Value

Label

Bike

0

Motorbike

Car

1

Car

Truck

2

Truck

The Label column in the preceding table shows the literal to use, the actual value will be the label Id, such as @ConWHS:Motorbike or @ConWHS:ConWHS2 if you are using numbers for label IDs.
  1. To add each symbol, or element as it is referred to in the editor, right-click on the Enum and choose New Element, as shown in the following screenshot:
  1. Complete the property sheet as per the table, and repeat for each required element.
  2. You can reorder the elements using the Alt + up key and Alt + down key, but this will only affect how they are displayed in the editor. You must also change Enum Value.
  3. Press the Save or Save all buttons in the toolbar.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.222.83.185