web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

How to get LedgerDimension worker in X++ code

(1) ShareShare
ReportReport
Posted on by 405

Hello everyone,

I recently started working on a feature to create ledger journal entries through a new form that handles loan requests from employees.

The process starts when an authorized person submits a loan request for a specific employee. This creates a new record in a custom table I made to store these requests. Then, someone else approves the request and clicks "Send for Payment." At this point, I need to follow a structure defined by the finance team, which includes a "Main Account" and "Personnel Number."

I wrote code that creates a row in ledgerJournalTable, followed by another row in ledgerJournalTrans, which contains the journal details.

However, I face an issue: sometimes I can get the LedgerDimension for the employee, and other times I can't. Here’s the code I use:

public static DimensionDynamicAccount generateLedgerDimension(DimensionAttributeRecId _recId, MainAccountNum _mainAccountId, HcmPersonnelNumberId _personnelNumber)
{
    RecId dimAttId_MainAccount;
    LedgerRecId ledgerRecId;
    MainAccount mainAccount;
    RefRecId recordvalue;
    DimensionAttribute dimensionAttribute;
    DimensionAttributeValue dimensionAttributeValue;
    DimensionSetSegmentName DimensionSet;
    DimensionStorage dimStorage;
    LedgerAccountContract LedgerAccountContract = new LedgerAccountContract();
    DimensionAttributeValueContract ValueContract;
    List valueContracts = new List(Types::Class);
    dimensionAttributeValueCombination dimensionAttributeValueCombination;

    mainAccount = MainAccount::findByMainAccountId(_mainAccountId);
    recordvalue = DimensionHierarchy::getAccountStructure(mainAccount.RecId, Ledger::current());
    DimensionSet = DimensionHierarchyLevel::getDimensionHierarchyLevelNames(recordvalue);
    dimensionAttribute = DimensionAttribute::findByLocalizedName(DimensionAttribute::find(_recId).Name);

    if (dimensionAttribute)
    {
        dimensionAttributeValue = DimensionAttributeValue::findByDimensionAttributeAndValue(dimensionAttribute, _personnelNumber, true, true);
        if (dimensionAttributeValue)
        {
            ValueContract = new DimensionAttributeValueContract();
            ValueContract.parmName(dimensionAttribute.Name);
            ValueContract.parmValue(dimensionAttributeValue.CachedDisplayValue);
            valueContracts.addEnd(ValueContract);
        }
    }
    LedgerAccountContract.parmMainAccount(_mainAccountId);
    LedgerAccountContract.parmValues(valueContracts);
    dimStorage = DimensionServiceProvider::buildDimensionStorageForLedgerAccount(LedgerAccountContract);
    dimensionAttributeValueCombination = DimensionAttributeValueCombination::find(dimStorage.save());
    ledgerRecId = dimensionAttributeValueCombination.RecId;
    return ledgerRecId;
}

After meeting with the finance team, they confirmed that once they finish creating the Dimension structure, the system automatically generates Dimensions for all employees without exceptions.

I searched the DimensionAttributeValue table and found that employees for whom I couldn’t create a ledger journal didn’t have records there. However, when I manually created a ledger journal from the "Vendor Payment Journal" screen, the missing data was added automatically.

One solution I found is setting a parameter in DimensionAttributeValue::findByDimensionAttributeAndValue to true, which creates a new entry in the DimensionAttributeValue table.

This approach works but makes me uneasy because I don’t know if directly creating entries through code could cause issues or conflict with system logic.

What are the potential risks of this solution? Would this approach be safe?

Thank you all.

Categories:
I have the same question (0)
  • Suggested answer
    Jonas "Jones" Melgaard Profile Picture
    4,986 Most Valuable Professional on at
    I feel safe having this in my PROD. I did a trace creating a GL journal, and the standard dimension segment control is using that method with the parameter set true.
    DimensionAttributeValue::findByDimensionAttributeandValue is calling DimensionAttributeValue::findByDimensionAtributeAndValueNoError, so it's not that different..
     
    You should find more example of this if you do a trace when you enter a journal with a new employee.
  • Ali AbdAlNasser Profile Picture
    405 on at
    Hello Jonas,
    Does this mean that my code is safe and does not cause conflicts with the system logic?
  • Jonas "Jones" Melgaard Profile Picture
    4,986 Most Valuable Professional on at
    Yes, I'd say so. But as always you need to test this together with the finance team.
    You can find example on this forum where they use findByDimensionAttributeAndValue with the 4th parameter set to true.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 551 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 450 Super User 2025 Season 2

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 278 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans