Convert enum value to STR in Electronic report D365 FO

Purpose:

The purpose of this document is to demonstrate how we can we get enum values in Electronic report

 X++ based on a business logic.

Product:

Dynamics 365 for Finance and Operations, Platform Update 9.

Development approach:

Customization through CODE, we need to  get enum values in Electronic report

Development:

Create a class to get enum values into electronic report... in Electronic report system wont allow us to provide values as enum for this we required to convert our desired enum value to string and need to bind that method to our value in model mapping 

Please find the method definition as follows.


Below in my requirement i want to assign TransactionType and LedgerPostingType values into my report so that i was added logic like below... here code will convert enum to str for required values

    public TransactionType      voucherType = TransactionType::Sales;

    public LedgerPostingType    PurchaseLedgerAccountName = LedgerPostingType::CustBalance;

    public Map enumStrsnew    = new Map(Types::Integer, Types::Class);

    private static EnumId enumNumvoucherType = enumNum(TransactionType);

    private static EnumId enumPurchaseLedgerAccountName = enumNum(LedgerPostingType);



// Actal method helps to covert enum value to str

    public str enum2StrNew(EnumId _enumId, anytype _val)
    {
        str ret;
        Map map;
        if (enumStrsnew.exists(_enumId))
        {
            map = enumStrsnew.lookup(_enumId);
        }
        else
        {
            map = new Map(Types::Integer, Types::String);
            enumStrsnew.insert(_enumId, map);
        }
        if (map.exists(_val))
        {
            ret = map.lookup(_val);
        }
        else
        {
            ret = enum2Str(_val);
            map.insert(_val, ret);
        }
        return ret;
    }


///calling above  method to return desired output and map this method to value in model mapping 

    public str parmPurchaseLedgerAccountName(LedgerPostingType _PurchaseLedgerAccountName = PurchaseLedgerAccountName)

    {

        PurchaseLedgerAccountName = _PurchaseLedgerAccountName;

        return this.enum2StrNew(enumPurchaseLedgerAccountName, PurchaseLedgerAccountName);

    }



///calling above  method to return desired output and map this method to value in model mapping

    public str parmvoucherType(TransactionType _voucherType = voucherType)

    {

        voucherType = _voucherType;

        return this.enum2StrNew(enumNumvoucherType, voucherType);

    }

Comments