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

Comments

Popular posts from this blog

Customization on Sales invoice Report in D365 F&O

75) COC - Create a coc of the table modified method

46) D365 FO: SHAREPOINT FILE UPLOAD USING X++