I am writing a Dynamics Business Central API v2.0 AL extension that creates a new page for my organization. The API is being used in a Power Automate flow to pass data back and forth to a Power app that we created. The page uses the "items" table as the source table and contains fields with a variety of data types Code[20], Text, Boolean, etc., but the ones giving me a problem are the enums. I have created a page field property for an enum field from "Item" like this:
field(Replenishment_System; Rec."Replenishment System") // Rec."Replenishment System" is type: (field) Type: Enum Microsoft.Inventory.Item."Replenishment System"
{
Caption = 'Replenishment System';
}
The API allows Power Automate to call "Create Record" correctly in a flow, but when calling "Find One Record", the API returns the value containing Unicode in the string rather than all text.
For example, what I want it to return: "Prod. Order".
What it actually returns: "Prod_x002E__x0020_Order"
I have tried changing the following in the field() property parameter changes:
field(Replenishment_System; Format(Rec."Replenishment System")) . . .
field(Replenishment_System; Enum::"Replenishment System".Names.Get(Enum::"Replenishment System".Ordinals().IndexOf(Rec."Replenishment System".AsInteger()))) . . .
field(Replenishment_System; CustomProcedure(Rec."Replenishment System")) . . .
All of these flagged as "read-only" and won't allow writing to the items table.
I'm very new to AL, so I've read countless pages of the documentation surrounding enums (and many other things for that matter), but I have found it to be sparse and challenging to sift through.
Is there a solution that would allow this page field to read the enum value without the Unicode and allow it to write to the item table field as well?
My current line of thinking is to leave the signature as the AL page wizard generates it and somehow overload some sort of read trigger, but I don't know if AL has or allows for that sort of functionality.
UPDATE:
After reading this article posted in the answer below, I implemented option 6 in our API considering our use case doesn't require filtering on the enum fields.
As a side note, I finished the Microsoft Learn modules for AL which fills in the gaps of the AL documentation. This gave critical perspective on how everything works together.
At the time of writing (March, 2025) Business Central API's support two schema versions:
1.0
which uses Captions for enums2.0
which uses strict typing for enumsAs you are using the Business Central connector in Power Automate, you will be using schema version 2.0
.
The method for handling the strict typing is using C#'s XmlConvert.EncodeName(value)
to encode the values.
This means they can also be decoded and Power Automate has a built-in function DecodeXmlName
for this.
Additionally there is also an EncodeXmlName(value)
to encode values.
You should handle this behavior in Power Automate and not try to force your API to behave in a specific way.
My answer is based on Arend-Jan Kauffmann's blog post about the subject - so credit goes to him.