Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

Mainaccount list Class/Method

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hi,

Do you know what is the class/method to get an account list? I am tring to modify the following code, this code retrieves the structure/dimentions for a specific account. I am tring to modify this code addinng a loop for all accounts , but I am not sure how to get the complete listo of account.

Thanks in advance.

code:

static void dimensionByAccounts(Args _args)

{

    DimensionAttributeValueCombination  dimAttrValueComb;

 

    DimensionStorage        dimensionStorage;

 

    DimensionStorageSegment segment;

    int                     segmentCount, segmentIndex;

    int                     hierarchyCount, hierarchyIndex;

    str                     segmentName, segmentDescription;

    SysDim                  segmentValue;

 

    DimensionHierarchyLevel  dimensionHierarchyLevel;

    RefRecId recordvalue;

    DimensionAttributeValueCombination dimCombination;

    MainAccount  mainAccount;

    ;

 

   mainAccount=

MainAccount::findByMainAccountId('1110010101016',false,LedgerChartOfAccounts::findByName(curext()).RecId);

    recordvalue=DimensionHierarchy::getAccountStructure(mainAccount.RecId);

 

    select  recid from dimCombination where  dimCombination.MainAccount==mainAccount.RecId

               && dimCombination.AccountStructure==recordvalue;

 

    dimAttrValueComb = DimensionAttributeValueCombination::find(dimCombination.RecId);

    setPrefix("Breakup for " + dimAttrValueComb.DisplayValue);

 

    dimensionStorage = DimensionStorage::findById(dimAttrValueComb.RecId);

    if (dimensionStorage == null)

    {

        throw error("No existe una dimencion para la cuenta");

    }

    hierarchyCount = dimensionStorage.hierarchyCount();

    for(hierarchyIndex = 1; hierarchyIndex <= hierarchyCount; hierarchyIndex++)

    {

        setPrefix(strFmt("Hierarchy: %1", DimensionHierarchy::find(dimensionStorage.getHierarchyId(hierarchyIndex)).Name));

 

        segmentCount = dimensionStorage.segmentCountForHierarchy(hierarchyIndex);

        //Loop through segments and display required values

        for (segmentIndex = 1; segmentIndex <= segmentCount; segmentIndex++)

        {

            segment = dimensionStorage.getSegmentForHierarchy(hierarchyIndex, segmentIndex);

            if (segment.parmDimensionAttributeValueId() != 0)

            {

               // Dimension Name

                segmentName = DimensionAttribute::find(DimensionAttributeValue::find(segment.parmDimensionAttributeValueId()).DimensionAttribute).Name;

 

                 // segment value- Dimension Value

                segmentValue        = segment.parmDisplayValue();

 

                //Description for dimension)

                segmentDescription  = segment.getName();

                info(strFmt("DimensionName:%1: Value:%2,Description: %3", segmentName, segmentValue, segmentDescription));

            }

        }

    }

}

*This post is locked for comments

  • enricoariel Profile Picture
    enricoariel 60 on at
    RE: Mainaccount list Class/Method

    just to expand on the answer of Guruprasanna M here a full working job:

    static void Job8(Args _args)
    {
    LedgerChartOfAccountContract chartOfAccounts = new LedgerChartOfAccountContract();
    DimensionServiceProvider serviceProvider = new DimensionServiceProvider();
    List mainAccountsList;
    MainAccountContract contract;
    ListEnumerator mainAccountsListEnumerator;
    chartOfAccounts.parmName("YOUR chart of account name");

    mainAccountsList = serviceProvider.getMainAccountsForLedgerChartOfAccount(chartOfAccounts);
    mainAccountsListEnumerator = mainAccountsList.getEnumerator();

    while (mainAccountsListEnumerator.moveNext())
    {
    contract = mainAccountsListEnumerator.current();
    info(strFmt('%1 - %2', contract.parmMainAccountId(), contract.parmName()));
    }
    }

    you can find the full list of parameters here: 

    \Classes\DimensionServiceProvider\getMainAccountsForLedgerChartOfAccount

  • Guruprasanna Profile Picture
    Guruprasanna 1,044 on at
    RE: Mainaccount list

    Hi lmingora,

    Along with Sathish suggestion, you can make use of getMainAccountsForLedgerChartOfAccount methods of the DimensionServiceProvider standard ax class. Here you need to just pass the 'LedgerChartOfAccount' to this method it will returns you the list of main accounts. Please refer below code.

    LedgerChartOfAccountContract    chartOfAccounts = new LedgerChartOfAccountContract();

           chartOfAccounts.parmName("YourCOA");

           DimensionServiceProvider    serviceProvider = new DimensionServiceProvider();

           List mainAccountsList = serviceProvider.getMainAccountsForLedgerChartOfAccount(chartOfAccounts);

    Regards

    Guru

  • Suggested answer
    Satish Panwar Profile Picture
    Satish Panwar 14,647 on at
    RE: Mainaccount list

    Hi Imingora,

    The table which store the main accounts is "MainAccount". What you need to do is first get the Chart of account used for the company. Once you have that, use that to filter records in mainaccount and you will get all the accounts. If you have only one legal entity in your environment, just loop through all records in "MainAccount' table.

    Below is SQL representation.

    select * from MAINACCOUNT where LedgerChartOfAccounts = 22565420920

    Thanks,

    Satish Panwar

    Please take time to click 'Yes' against the answers that help you guide in right direction to help other community members.

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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,711 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,466 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans