AL icon indicating copy to clipboard operation
AL copied to clipboard

Enum issue

Open fehebo opened this issue 7 years ago • 10 comments

Hello, We have 3 extensions

  1. Base – Contains “Base Enum”; enum 50100 "Base Enum" { Extensible = true; value(0; None) { Caption = ' '; } value(1; One) { Caption = 'One'; } value(2; Two) { Caption = 'Two'; } }
  2. Ext1 – Contains “Ext1 Enum”, that extends “Base Enum”; enumextension 50150 "Ext1 Base Enum" extends "Base Enum" { value(3; Three) { Caption = 'Tree'; } }
  3. Ext2 – Contains “Ext2 Enum”, that extends “Base Enum”; enumextension 50100 "Ext2 Base Enum" extends "Base Enum" { value(4; Four) { Caption = 'Four'; } value(5; Five) { Caption = 'Five'; } }

Publishing and installation: Step 1 – publishing Base; Step 2 – publishing Ext2 with dependency on Base; Step 3 – publishing Ext1 with dependency on Base;

If we use "id": "86efc993-7f41-48fb-9918-f689c52c8619" for Ext2 then: Step 1 Result image Step 2 Result image Step 3 Result image Enum values were corrupted (numbers don’t match values): Id = 3 – Name = Four Id = 4 – Name = Five Id = 5 – Name = Three

If “id” for Ext2 is changed(for example: "c52b2524-0a71-440d-9303-f632428e6455") then: Step 1 Result image Step 2 Result image Step 3 Result image Same behavior if extend enum from C/AL object. Somehow ids specified in app.json cause unpredictable behavior of enums. Can you please investigate this issue? Example.zip

fehebo avatar Dec 17 '18 09:12 fehebo

Seems related to the AL language. Transferring issue to AL repo.

JesperSchulz avatar Dec 17 '18 10:12 JesperSchulz

It is deterministic and the AppId is involved. We are considering to add a way of arranging enum-values in the future, but we don't have a timeline for that.

esbenk avatar Dec 17 '18 14:12 esbenk

How about arranging values... by their value? What's the point of assigning values to Enums if BC isn't going to respect that order? There should be no other variables involved.

I've come across this issue and the order of the values seems to be determined by the timestamp associated with AppID, i.e., newer extensions will show up before older ones.

This seems like a huge oversight and should be fixed ASAP because it most certainly leads to data corruption and makes the Enum functionality totally counterproductive.

sonicadv27 avatar Jun 12 '19 16:06 sonicadv27

The ordinal value assigned to the individual enum values are used for persistence. That AppId have no influence on the persisted values. This will not lead to data corruption.

The Order in the UI is not related to the persisted values.

Extensions gets their values appended to the original values. And yes currently the AppId dictates that order.

We have on backlog to support re-ordering of enum values in the UI, but we don't have an ETA for that.

esbenk avatar Jun 12 '19 18:06 esbenk

But that's the thing: the problem is not the order in the UI, the values themselves get corrupted so there's definitely data corruption.

Somehow the numbers assigned to the values do not mirror the values attributed to the options.

In any case, there's absolutely no reason for Enums not to respect the order of the values, especially since they were introduced to replace Option strings, which did worked like this.

sonicadv27 avatar Jun 12 '19 20:06 sonicadv27

The UI is not ordered by the enum value ordinals. The ordinal values used in enum extensions are supposed to be in the partner range to avoid collisions. The enum values are used for persistence, not for any ordering in the UI.

esbenk avatar Jun 13 '19 05:06 esbenk

Again, i'm not talking about the order in the UI. I'm talking about data corruption when new Enum options are added, because that certainly happens.

sonicadv27 avatar Jun 13 '19 08:06 sonicadv27

Please provide a repro.

esbenk avatar Jun 13 '19 10:06 esbenk

Hi! Thank you for taking the time to share this request — we appreciate the thoughtful feedback and understand how important extensibility is for partners building on Business Central.

This repository is focused on issues related to the AL compiler and developer tools. Extensibility requests like this — which require changes to the base application or platform — are best tracked through https://github.com/Microsoft/ALAppExtensions or our Ideas forum at https://aka.ms/BCIdeas.

We encourage you to post your request there (or vote it up if it already exists) so it gets the visibility it deserves. We actively monitor top ideas and consider them for future releases.

Thank you for helping shape the future of Business Central!

SBalslev avatar Mar 13 '26 15:03 SBalslev