Hi All,
Recently I came up with a requirement to validate the combination of Main Account and Default Dimensions in D365 F&&SCM, so sharing the piece of code, hope it help someone.
public static boolean validateAccountStructureAndDefaultDim(
DimensionDefault _defaultDimensions,
LedgerDimensionBudget _ledgerDimension,
TransDate _transactionDate)
{
DimensionValidationStatus dimensionValidationStatus = DimensionValidationStatus::Valid;
boolean ret;
LedgerDimensionAccount ledgerDimensionAccount = DimensionDerivationDistributionRule::buildLedgerDimension(_ledgerDimension, _defaultDimensions);
dimensionValidationStatus = LedgerDimensionValidationHelper::validateByTree(ledgerDimensionAccount, _transactionDate, true, true);
if (dimensionValidationStatus == DimensionValidationStatus::Valid)
{
ret = true;
}
return ret;
}
This piece of code can be used as below:
//Select all the lines for validation
while select LedgerDimension, DefaultDimension, LineNum from custInvoiceLine
where custInvoiceLine.ParentRecId == _custInvoiceTable.RecId
{
if (!custInvoiceLine.DefaultDimension) // Validation to check if atleast 1 financial dimension value is specified.
{
canSubmitToWorkflow = checkFailed("Atleast 1 Financial Dimension value must be specified.");
}
if (canSubmitToWorkflow)
{
// Call to our method
canSubmitToWorkflow = QTQ_CustFreeInvoiceWorkflow::validateAccountStructureAndDefaultDim(custInvoiceLine.DefaultDimension, custInvoiceLine.LedgerDimension, today());
}
}