Thursday, June 10, 2021

Job to get ledger dimension of voucher transactions(GeneralJournalAccountEntry.LedgerDimension) when Invoice sales order in D365FO

As we know, if we do sales order invoice then sales order revenue transactions will get created in voucher transactions. here ledger dimension field will generate in GeneralJournalAccountEntry table based on the item default dimension and ledger dimension then it will apply fixed dimensions of main account.

Below job will help you to get the same, hope this helps and will come up with another interesting blog.


class JP_GetLedgerDimension
{
    
    /// <summary>
    /// Runs the class with the specified arguments.
    /// </summary>
    /// <param name = "_args">The specified arguments.</param>
    public static void main(Args _args)
    {
        MainAccount mainAccount;
        LedgerDimensionAccount ledgerDimension;
       
        DimensionHierarchyId accountStructureId = DimensionHierarchy::getAccountStructure(5637144906);//Mainaccount recId


        ledgerDimension = JP_GetLedgerDimension::getLedgerDimensionFromAccountAndDimWithoutDerivedDimensions(5637144906, accountStructureId,5637166190);//mainaccount recid, AccountStructureId, default dimension of Item

        ledgerDimension = JP_GetLedgerDimension::applyFixedDimensions(ledgerDimension);

        Info(strFmt("%1", ledgerDimension));
        
    }

    public static LedgerDimensionAccount applyFixedDimensions(LedgerDimensionAccount _ledgerDimension)
    {
    
        _ledgerDimension =
            LedgerDimensionFacade::serviceApplyFixedDimensions(_ledgerDimension);
    
        return _ledgerDimension;
    }

    public static LedgerDimensionAccount getLedgerDimensionFromAccountAndDimWithoutDerivedDimensions(recId _mainAccountId, recId _accountStructureId, DimensionDefault _defaultDimensionId = 0)
    {
        LedgerDimensionDefaultingEngine dimDefaultingEngine;
        List dimensionSources;

        // Validate input parameter
        if (!_mainAccountId || !_accountStructureId)
        {
            throw error(Error::wrongUseOfFunction(funcName()));
        }

        dimensionSources = new List(Types::Class);
        dimensionSources.addEnd(LedgerDimensionDefaultingEngine::getDefaultDimensionSpecifiers(_defaultDimensionId));
        dimDefaultingEngine = LedgerDimensionDefaultingEngine::constructForMainAccountId(_mainAccountId, _accountStructureId);
        dimDefaultingEngine.applyDimensionSources(dimensionSources);

        return dimDefaultingEngine.getLedgerDimension();
    }

}

No comments:

Post a Comment