Tuesday, 3 December 2024

Validate the Ledger dimension values in d365 FO

 MainAccount mainAccountId = LedgerDimensionFacade::getMainAccountFromLedgerDimension(_ledgerPostingTransaction.LedgerDimension);

DimensionHierarchyId accountStructureId = DimensionHierarchy::getAccountStructure(mainAccountId.RecId);
if (accountStructureId)
{

LedgerDimensionDefaultingEngine dimDefaultingEngine;
List dimensionSources;

// Validate input parameter
if (!mainAccountId.RecId|| !accountStructureId)
{
throw error(Error::wrongUseOfFunction(funcName()));
}

dimensionSources = new List(Types::Class);
dimensionSources.addEnd(LedgerDimensionDefaultingEngine::getDefaultDimensionSpecifiers(inventJournalTrans.BTCOffsetDefaultDimension));
dimDefaultingEngine = LedgerDimensionDefaultingEngine::constructForMainAccountId(mainAccountId.RecId, accountStructureId);
dimDefaultingEngine.applyDimensionSources(dimensionSources);

LedgerDimensionAccount ledgerDimensionAccountCustom = dimDefaultingEngine.getLedgerDimension();
generalJournalAccountEntry.LedgerDimension = ledgerDimensionAccountCustom;

}
else
{
throw error(strFmt("@SYS4009834", MainAccount::find(mainAccountId.RecId).MainAccountId));
}

No comments:

Post a Comment

Clean up jobs in D365FO

  https://anithasantosh.wordpress.com/2024/11/07/clean-up-jobs-in-d365fo/