Thursday, June 15, 2023

Code to get Opening balance for Ledgerdimension in D365

     public static void main(Args _args)

    {

        LedgerBalanceDimAttrValueComboAmounts   ledgerBalance;

        AmountMst                               opSum;

        DimensionAttributeValueCombination      dim;

        select dim where dim.RecId ==  68719651020; // recid of (110110-001-022)

        date dateTime,datetimeloc,fromdate,todate;

        fromdate = mkDate(01,01,2017);

        todate = mkDate(31,12,2017);

        dateTime = any2Date(DateTimeUtil::addYears(fromdate , -1));

        datetimeloc = any2Date(DateTimeUtil::addYears(todate , -1));

        ledgerBalance = LedgerBalanceDimAttrValueComboAmounts::construct();

        ledgerBalance.parmIncludeRegularPeriod(true);

        ledgerBalance.parmIncludeOpeningPeriod(true);

        ledgerBalance.parmIncludeClosingPeriod(false);

        ledgerBalance.parmAccountingDateRange(dateTime, datetimeloc);

        ledgerBalance.calculateBalance(dim);

        opSum = ledgerBalance.getAccountingCurrencyBalance();

        Info(strFmt("opening balance : %1 ",opSum));

     }

....................

Other Way:

       LedgerTrialBalanceDP        ledgerTrialBalanceDP;

       LedgerTrialBalanceContract  ledgerTrialBalanceContract;

       LedgerTrialBalanceTmp       ledgerTrialBalanceTmp,ledgerTrialBalanceTmpLoc;

       LedgerTrialBalanceTmp       ledgerTrialBalanceTmpCustom;

       DimensionHierarchy          dimensionHierarchy;

       List                        postingLayer;

       ledgerTrialBalanceDP        = new LedgerTrialBalanceDP();

       ledgerTrialBalanceContract  = new LedgerTrialBalanceContract();

       postingLayer                = new List(Types::Enum);

       dimensionHierarchy          = DimensionHierarchy::getMainAccountFocus();

       postingLayer.addEnd(CurrentOperationsTax::Current);

       ledgerTrialBalanceContract.parmFromDate(mkDate(01,01,2017));

       ledgerTrialBalanceContract.parmToDate(mkDate(31,12,2017));

       ledgerTrialBalanceContract.parmIncludeOpening(false);

       ledgerTrialBalanceContract.parmIncludeClosing(false);

       ledgerTrialBalanceContract.parmPostingLayers(postingLayer);

       ledgerTrialBalanceContract.parmPrimaryDimensionFocus("MA+BU+DEPT");

       ledgerTrialBalanceContract.parmIncludeClosingAdjustments(false);

       ledgerTrialBalanceContract.parmIncludeClosingTransactions(false);

       ledgerTrialBalanceContract.parmDisplayMainAccountCategory(false);

       ledgerTrialBalanceDP.parmDataContract(ledgerTrialBalanceContract);

       ledgerTrialBalanceDP.setTrialBalanceTmpTable(ledgerTrialBalanceTmp);

       ledgerTrialBalanceDP.processReport();

       ledgerTrialBalanceTmp = ledgerTrialBalanceDP.getLedgerTrialBalanceTmp();

       while  select ledgerTrialBalanceTmp

              where ledgerTrialBalanceTmp.DimensionValues[1]=="110110"

               &&ledgerTrialBalanceTmp.DimensionValues[2]=="001" //businessunit

              &&ledgerTrialBalanceTmp.DimensionValues[3]=="022" //department

       {

           Info(strFmt("%1",ledgerTrialBalanceTmp.OpeningBalance));

       }







No comments:

Post a Comment