hljs.configure({cssSelector: "code"}); hljs.highlightAll();

Wednesday, June 9, 2021

X++ code to get financial dimensions in AX7/D365


public void dimensions(defaultDimension)

{

VendParameters                          vendParameters = VendParameters::find();

DimensionAttribute                      attribute                = DimensionAttribute::findByName(vendParameters.DepartmentDim);

DimensionAttribute                      attributeProfitCentre    = DimensionAttribute::findByName(vendParameters.SiteDim);

MainAccountNum                          mainAccountNum;       

dimensionAttributeValueSetItemView.clear();

select DisplayValue from dimensionAttributeValueSetItemView

     where dimensionAttributeValueSetItemView.DimensionAttributeValueSet == DefaultDimension

        && dimensionAttributeValueSetItemView.DimensionAttribute    == attribute.RecId;

DimensionValue = dimensionAttributeValueSetItemView.DisplayValue;

dimensionAttributeValueSetItemView.clear();

select DisplayValue from dimensionAttributeValueSetItemView

      where dimensionAttributeValueSetItemView.DimensionAttributeValueSet == DefaultDimension

           && dimensionAttributeValueSetItemView.DimensionAttribute  ==  attributeProfitCentre.RecId;

DimensionValueprofitCentre = dimensionAttributeValueSetItemView.DisplayValue;

mainAccountNum = MainAccount::findByMainAccountId(LedgerDimensionFacade::getMainAccountIdFromLedgerDimension(paymode.InterCompanyLedgerDimension)).MainAccountId;

ledgerDim = CreateAndPostVendorJournal::getDimension(mainAccountNum,DimensionValue,DimensionValueprofitCentre);

}

//custom method

    public static RecId getDimension(str _ledgerAccount,DimensionValue _costCentre,DimensionValue _profitCentre)

    {

        //DimensionServiceProvider            DimensionServiceProvider    = new DimensionServiceProvider();

        LedgerAccountContract               LedgerAccountContract       = new LedgerAccountContract();

        DimensionAttributeValueContract     ValueContract;

        List                                ListValueContract = new List(Types::Class);

        dimensionAttributeValueCombination  dimensionAttributeValueCombination;

        DimensionStorage                    dimStorage;

        VendParameters salesParameters = VendParameters::find();

        if(_costCentre)

        {

            ValueContract = new DimensionAttributeValueContract();

            ValueContract.parmName(salesParameters.DepartmentDim);

            ValueContract.parmValue(_costCentre);

            ListValueContract.addEnd(ValueContract);

        }

        if(_profitCentre)

        {

            ValueContract = new DimensionAttributeValueContract();

            ValueContract.parmName(salesParameters.SiteDim);/\                              ValueContract.parmValue(_profitCentre);

            ListValueContract.addEnd(ValueContract);

        }

        LedgerAccountContract.parmMainAccount(_ledgerAccount);

        //LedgerAccountContract.parm

        LedgerAccountContract.parmValues(ListValueContract);

        dimStorage = DimensionServiceProvider::buildDimensionStorageForLedgerAccount(LedgerAccountContract);

        dimensionAttributeValueCombination = DimensionAttributeValueCombination::find(dimStorage.save());

        return dimensionAttributeValueCombination.RecId;

    }





 

No comments:

Post a Comment