Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

How to select values from table based on parameter value?

Posted on by 920

Hi,

I want to select record from table based on parameter value in method:

public void findElementsOfRole(str _roleName, int64 _versionNumber)
{
      
    str                    matrixrole;
    EUKSecurityTreeNode     _securityTreeNode;
    matrixrole           = _roleName;
    select _securityTreeNode where _securityTreeNode.matrixName==matrixrole;          
}

when I run my code I don't get any record?
What is the error in this code?

*This post is locked for comments

  • BASMA Profile Picture
    BASMA 920 on at
    RE: How to select values from table based on parameter value?

    I use my code in new class then I call this class in findElementsOfRole() but the same problem.


    knowing that teh parameter _roleName is the securityRole.AOTName.

  • BASMA Profile Picture
    BASMA 920 on at
    RE: How to select values from table based on parameter value?

    Hi,

    I haven't the dataArea in my table so the data of all company  is saved in this table.

  • Suggested answer
    nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: How to select values from table based on parameter value?

    Then we know that the problem is not in the code that you have shared with us. It's somewhere else.

    Maybe your class is running in different company context and there is no data in your table for that company.

    What if you add this line in your job and in your class - it will show which company is used at the moment:

    info(curExt());

    If you still have problems, please share more details and more code.

  • BASMA Profile Picture
    BASMA 920 on at
    RE: How to select values from table based on parameter value?

    When I try your suggestion ,it works and I get the exact values.

    I add new method in my class to find the exact values from EUKSecurityTreeNode, then I call this method in "findElementsOfRole" I get the same problem.

  • Suggested answer
    nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: How to select values from table based on parameter value?

    Maybe you could try to call your class from your job to make sure you are using the same search criteria in both.

    And also to make it easier, you could add an infolog in your class method for now. Something like this. Please share the results with us.

    static void Job2(Args _args)
    {
    
        Str60   matrixrole = "Euk-000047";
        EUKSecurityTreeNode     eukSecurityTreeNode;
    YourClass yourClass = new yourClass(); select RecId,MatrixRole from eukSecurityTreeNode
    where eukSecurityTreeNode.MatrixRole == matrixrole;
    if(eukSecurityTreeNode)
    { info(strFmt("menu %1",eukSecurityTreeNode.MatrixRole ));
    }

        yourClass.findElementsOfRole(matrixRole, 0); 
    }

    public void findElementsOfRole(str _roleName, int64 _versionNumber)
    {
        EUKSecurityTreeNode securityTreeNode;
        
        select securityTreeNode
            where securityTreeNode.MatrixRole == _roleName;  
    
        info(_roleName);
        if (securityTreeNode)
        {
            info("Found");
        }       
    }


  • BASMA Profile Picture
    BASMA 920 on at
    RE: How to select values from table based on parameter value?

    I means that the class works after I add this code  but the same problem exist.

  • nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: How to select values from table based on parameter value?

    Nice to hear that. Please mark the answer(s) verified if your problem is solved.

  • BASMA Profile Picture
    BASMA 920 on at
    RE: How to select values from table based on parameter value?

    Yes it works,

    until now the class works normally .

    Only the instruction which I added doesn't return any values.

  • nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: How to select values from table based on parameter value?

    And does your class work after fixing this typo?

  • BASMA Profile Picture
    BASMA 920 on at
    RE: How to select values from table based on parameter value?

    It is a typing error

    I use this code in my class:

     select RecId,MatrixRole from _securityTreeNode
               where _securityTreeNode.MatrixRole== matrixrole;


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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans