Wednesday 8 July 2020

Get default financial dimension values through X++ code

In the below example we will see how we can get the default financial dimension values from Purch line table.
Here we are using AxdDimensionUtil helper class to get the Dimension values.

Note:  we can replace PurchLine table with any table with DefaultDimension field.

static void Job5(Args _args)
{
    PurchLine   purchLine;
    Counter     i;
    container   conDim;
    //
    purchLine = PurchLine::find("WP00097201",1);   
    conDim = AxdDimensionUtil::getDimensionAttributeValueSetValue(purchLine.DefaultDimension);

    for (i=1 ; i<= conLen(conDim) ; i++)
    {
         info(conPeek(conDim,i));
    }
}

There are other ways to find default Dimensions values. The one above is one of them.

The same result can also be achieved using "DimensionAttributeValueSetStorage" class.


public DimensionValue getDimValue(int _index, DimensionDefault _defaultDim)
    {
       // #DocumationGL // List that matches the GL Export
       container       dimAttrList     = ['BPCTrialBalance', 'Customer', 'Department', 'Employee', 'IntercompanyCode', 'Project','ServiceCategory'];
        Name            dimAttribName   = conPeek(dimAttrList, _index);

        DimensionAttributeValueSet          DimensionAttributeValueSet;
        DimensionAttributeValueSetItem      DimensionAttributeValueSetItem;
        DimensionAttributeValue             DimensionAttributeValue;
        DimensionAttribute                  DimensionAttribute;
        ;

        select RecId from DimensionAttributeValueSet
            where DimensionAttributeValueSet.RecId == _defaultDim

        join DisplayValue from DimensionAttributeValueSetItem
            where DimensionAttributeValueSetItem.DimensionAttributeValueSet == DimensionAttributeValueSet.RecId

        join RecId from DimensionAttributeValue
            where DimensionAttributeValue.RecId == DimensionAttributeValueSetItem.DimensionAttributeValue

        join RecId from DimensionAttribute
            where DimensionAttribute.RecId == DimensionAttributeValue.DimensionAttribute
               && DimensionAttribute.Name == dimAttribName;

        return DimensionAttributeValueSetItem.DisplayValue;
    }

    display DimensionValue dimTrialBalance(ProjPostTransViewGL  _projPostTransView)
    {
        ProjJournalTrans    projJournalTrans;
        ProjCostTrans       projCostTrans;
        container   conDim;
        switch (_projPostTransView.ProjTransType)
        {
            case ProjTransType::Item:
            case ProjTransType::Hour:
            case ProjTransType::Revenue:
            case ProjTransType::OnAccount:
                select  DefaultDimension
                from    projJournalTrans
                where   projJournalTrans.TransId == _projPostTransView.TransId;
                
                return  this.getDimValue(1,projJournalTrans.DefaultDimension);

            case ProjTransType::Cost:
                select  DefaultDimension
                from    projCostTrans
                where   projCostTrans.TransId == _projPostTransView.TransId;

                return  this.getDimValue(1,projCostTrans.DefaultDimension);

            default :
                return '';
        }
    }

No comments:

Update NuGet package to new MS D365FO version

1. Import the NuGet package files from LCS for that particular version please take the PU version files only. a. Goto LCS-->Asset Libra...