Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Blogs / Jesús Almaraz blog / Option to Enum Conversion Tool

Option to Enum Conversion Tool

Introduction

In the previous post AL Enums late discovering (dynamics.com) I talked about Enums advantages over options, but I have stronger motivations to do something else about options to Enums conversion:
 
-  Problems panel is warning lots of future errors and misbehaving in option to Enum assignation.
 
-  In BC world all of us have a past, a heavy C/SIDE past, and I have converted projects from old C/SIDE code with over one hundred option fields. In fact, the work of convert this huge quantity of good C/AL code forced me to begin making my own VSCode extensions. I don´t want to make again apps that worked fine in C/SIDE, and I worked these years easing conversion minimizing manual operations.
Due these needs, in  my renaming extension JAL Variable Naming - Visual Studio Marketplace  I made an Options to Enums conversion tool. In sections bellow I will explain tool use comparing with manual conversion.

First: old way

The starting point is an old option field:
        field(69014; "TIP Test Choice"; Option)
        {
            OptionMembers = Never,All;
            OptionCaption = 'Never,All';
            DataClassification = CustomerContent;
        }
If we want to convert this into an Enum old way we have to do:
Make the .al Enum file:
enum 69000 "TIP Test Choice"
{
    Extensible = true;
    value(0; Never)
    {
        Caption = 'Never';
    }
    value(1; All)
    {
        Caption = 'All';
    }
}

Substitute in field option by enum type:
        field(69014; "TIP Test Choice"; enum "TIP Test Choice")
        {
            DataClassification = CustomerContent;
        }

With extension utility

Create initial csv file. Invoke command "JAL Option to enum. Create initial CSV":

Open in Excel the file created in step above and edit new Enum ids and names (can be duplicate, if applies to re-use):

When the excel is filled invoke "JAL Option to enum. Create new enums and substitute options" and select the edited csv file:

And this step will create the new .al Enum files in src/enum folder and automatically will substitute the options by Enums in tables and table extensions:
Hope this will be useful and please if you find any issue, place it on Git issues in Issues · JalmarazMartn/JAMALVariablenaming · GitHub

Comments

*This post is locked for comments