Sunday 3 January 2021

Validate the combination of Main Account (Ledger Dimension) with Financial Dimensions (Default Dimension)

 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());

            }

        }

No comments:

Post a Comment

Insert/Update or remove the default dimension value in D365 FSCM via x++

Use below method to insert/update the dimension values, just pass the parameter values to the method and it will return the updated value: p...