1

I am making a ssrs report and I need to call method that validate financial dimensions on general journal lines . which method should I call to validate financial dimension ?

I found this code but didn't work for me, all I need is to pass default dimension to method that validate financial dimensions

public  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;
}
  • Maybe the documentation of the financial dimensions framework can help you? https://learn.microsoft.com/en-us/dynamics365/fin-ops-core/dev-itpro/financial/financial-dev-home-page – FH-Inway Apr 27 '23 at 18:17
  • Do you have any code you've attempted? – Alex Kwitny Apr 28 '23 at 15:39

1 Answers1

1

Here's one method. There are various.

LedgerJournalTrans                      ledgerJournalTrans = LedgerJournalTrans::findRecId(5637869826, true);

// This is checking the offset ledger dimension, but you can check the primary as well.
DimensionValidationRequest              dimensionValidationRequest = DimensionValidationRequest::newForLedgerDimension(ledgerJournalTrans.OffsetLedgerDimension, ledgerJournalTrans.TransDate);
DimensionValidationStatusContract       dimensionValidationStatusContract;
List                                    validationMessages;
ListEnumerator                          messagesEnumerator;
boolean                                 isFirst, ok;

dimensionValidationRequest.parmDoValueSuspendedValidation(true);
dimensionValidationRequest.parmDoValueActiveDatesValidation(true);

dimensionValidationStatusContract = DimensionValidation::getStatus(dimensionValidationRequest);

info(strFmt("Is Valid: %1", dimensionValidationStatusContract.isValid()));

if (!dimensionValidationStatusContract.isValid())
{
    ok = false;
    isFirst = true;

    validationMessages = dimensionValidationStatusContract.parmValidationMessages();

    messagesEnumerator = validationMessages.getEnumerator();

    while (messagesEnumerator.moveNext())
    {
        // The first message provided is a warning, additional messages are informational
        // messages regarding the first message
        if (isFirst)
        {
            warning(messagesEnumerator.current());
            isFirst = false;
        }
        else
        {
            info(messagesEnumerator.current());
        }
    }
}

This is modified from \Classes\LedgerVoucherTransObject\check

Alex Kwitny
  • 11,211
  • 2
  • 49
  • 71
  • I want to validate default dimensions not offset dimensions can I replace this ? It will work or not ? – Menna Ahmed Apr 30 '23 at 08:39
  • I try your method but doesn't work well I want to get error with default dimensions but when values correct IT doesn't make valid = false , How can I pass default dimensions to this request ? – Menna Ahmed Apr 30 '23 at 10:21
  • Just change `ledgerJournalTrans.OffsetLedgerDimension` to `ledgerJournalTrans.DefaultDimension`. – Alex Kwitny May 01 '23 at 16:05
  • I tried it but didn't work , I got an error if dimensions valid and not valid I got an error in two cases – Menna Ahmed May 02 '23 at 06:58
  • Could you [edit] the question and add a more detailed description of the issues you encounter and the exact error messages and which line of the code causes them? – FH-Inway May 02 '23 at 15:37
  • I can't find which line get the exact error messages , but the exact error messages are like"You must select a value in the Department field in combination with the following dimensions values that are valid:" , "Main_Account 10112 is not an allowed value in combination with the following dimensions values that are valid:" , I want to know which method should I call to get these errors – Menna Ahmed May 03 '23 at 08:29
  • It sounds like the code is working correctly then?! `if (!dimensionValidationStatusContract.isValid())` lets you know they are valid/invalid and `validationMessages = dimensionValidationStatusContract.parmValidationMessages();` contains a `List` of the messages. Then `while (messagesEnumerator.moveNext())` is enumerating them and outputting them for you to see. – Alex Kwitny May 03 '23 at 16:42
  • it doesn't work for default dimensions , I have an issue to get an error of default dimensions – Menna Ahmed May 08 '23 at 07:01
  • Could you help us understand? In your comment on May 3rd, you write that you get an error message that reads like a validation result. In your last comment you write that you have an issue getting an error. Maybe it helps if you [edit] the question and describe what you expect as validation result and why? – FH-Inway May 09 '23 at 18:37