Get lable of enum value(Main Account Type) through computed column in view D365FO

  Purpose:
The purpose of this document is to demonstrate how we can get value in view through computed column X++ based on a business logic.
Product:
Dynamics 365 for Finance and Operations, Platform Update 9.
Development approach:
Customization through View , we need to show Enum values  lable in view based on DimensionLedgerAccountType  from voucher transactions
Development:
Create a view and added GneralJournalEntry and GneralJournalAccountEntry data sources. added computed column for this added method to bring enum lablebased on enum value. in our case bring value of "main account type lable"
Please find the method definition as follows.
public class Dimensionview extends common
{
    private static str mainaccounttypelable()
    {
        tableName leaveBankTransactionView = identifierStr(Dimensionview );
        DictEnum dictEnum = new DictEnum(enumNum(DimensionLedgerAccountType));
        Map enumValues = new Map(Types::String, Types::String);
        int counter;
        for (counter = 0; counter < dictEnum.values(); counter++)
        {
            enumValues.insert(int2str(dictEnum.index2Value(counter)), SysComputedColumn::returnLiteral(dictEnum.index2Symbol(counter)));
        }
        return SysComputedColumn::switch(SysComputedColumn::returnField(leaveBankTransactionView, identifierStr(MainAccount), fieldStr(MainAccount, Type )), enumValues, SysComputedColumn::returnLiteral(dictEnum.index2Symbol(counter)));
    }
}
    
    

Comments