AX / D365FO – Export Data Entity Enum fields labels in BYOD using Computed columns or Virtual fields

When you export a Data Entity in BYOD the base enums fields values are shown as integer values.

This is a big problem because it’s very difficult to understrand the real value of the field.

To solve this issue you can extend the standard data entity or modify a custom one using a virtual field or a computed column.

Using computed column

In this example we’ll add a new computed column to decode the PostingType enum field description.

First of all create an extension of the Data Entity (GeneralJournalAccountEntryEntity) and add the new virtual field (Al0PostingTypeDesc) by right-clicking on fields > String unmapped value

Set “Is Computed field” property to YES

Now create a new class and add a static method (getPostingTypeDescription()) like in example shown below

[ExtensionOf(tableStr(GeneralJournalAccountEntryEntity))]
final class Al0GeneralJournalAccountEntryEntity_Extension

{

     public static str getPostingTypeDescription()
        {
            SysDictEnum dictEnum = new SysDictEnum(enumNum(LedgerPostingType));
            Map mapping = SysComputedColumn::comparisionExpressionMap();

            for (int i = 0; i < dictEnum.values(); i++)
            {
                mapping.insert(
            SysComputedColumn::comparisonLiteral(dictEnum.index2Value(i)),
            SysComputedColumn::returnLiteral(dictEnum.index2Label(i)));
            }

            str comparisonField = SysComputedColumn::comparisonField(
        tableStr(GeneralJournalAccountEntryEntity),
        dataEntityDataSourceStr(GeneralJournalAccountEntryEntity, GeneralJournalAccountEntry),
        fieldStr(GeneralJournalAccountEntry, PostingType));

            return SysComputedColumn::switch(comparisonField, mapping, SysComputedColumn::returnLiteral(''));
        }
}

Now return to your data entity computed column and set the method (Al0GeneralJournalAccountEntryEntity_Extension::getPostingTypeDescription) to the “DataEntityView Method” property.

Create an extension of the Staging table and add the custom field manually

Build your project and sync the db

Using Virtual field

In this example we’ll add a new virtual field to decode the PostingType enum field description.

First of all create an extension of the Data Entity (GeneralJournalAccountEntryEntity) and add the new virtual field (Al0PostingTypeDesc) by right-clicking on fields > String unmapped value

Set “Is Computed field” property to NO

Then create a new class to extend the Data Entity Post Load method.

This customization will decode the integer value of the enum into the real description

[ExtensionOf(tableStr(GeneralJournalAccountEntryEntity))]
final class Al0GeneralJournalAccountEntryEntity_Extension
{

    public void postload()
    {
        next postload();
       
        GeneralJournalAccountEntryEntity generalJournalAccountEntryEntity = this;
        DictEnum enum = new DictEnum(enumName2Id("LedgerPostingType"));
        generalJournalAccountEntryEntity.Al0PostingTypeDesc = int2Str(enum.index2Value(generalJournalAccountEntryEntity.PostingType));

    }
}

Create an extension of the Staging table and add the custom field manually

Build your project and sync the db

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s