Skip to main content

Notifications

Microsoft Dynamics AX (Archived)

How to filter data based on multiple lookup??

Posted on by 920

Hi ,

I have form :

0211.form.png

in this form I want to get the list of user assign to the role and the organization choiced in the filter.

this is the structure of form:

0250.structure.png

*This post is locked for comments

  • BASMA Profile Picture
    BASMA 920 on at
    RE: How to filter data based on multiple lookup??

    I add  this :

         while select userinfo1 exists    join securityUserRole        where securityUserRole.SecurityRole == securityRole.RecId && securityUserRole.User  == userinfo1.id

                                notexists join omUserRoleOrganization  where omUserRoleOrganization.SecurityRole  == securityRole.RecId && omUserRoleOrganization.User  == userinfo1.id

                                //notexists join omUserRoleOrganization  where omUserRoleOrganization.User   == securityUserRole.user

         {

             Utilisateur.add(userinfo1.name);

         }

    and it works .

  • Suggested answer
    Rustem Galiamov Profile Picture
    Rustem Galiamov 8,072 on at
    RE: How to filter data based on multiple lookup??

    Hi BASMA!

    Try to add omUserRoleOrganization.OMInternalOrganization == omInternalOrganization.RecId to second statement where used notexists join

    while select userinfo1 exists join securityUserRole 
        where securityUserRole.SecurityRole == securityRole.RecId 
           && securityUserRole.User         == userinfo1.id
    notexists join omUserRoleOrganization 
        where omUserRoleOrganization.User                   == securityUserRole.user
    && omUserRoleOrganization.OMInternalOrganization == omInternalOrganization.RecId { Utilisateur.add(userinfo1.name); }


     

  • BASMA Profile Picture
    BASMA 920 on at
    RE: How to filter data based on multiple lookup??

    Hi Rustem, when I use this method:

    for example when I have user that assigned to role A with all organization and assigned to another role B in organization A.

    When I filter with role A and with any organization I don't get the name of user.

    Utilisateur.clear();
    //select the list of user assigned to the role and organization
    if(Role.text() != "" && Organisation.text() != "")
    {
    while select userinfo1 exists join omUserRoleOrganization where omUserRoleOrganization.SecurityRole == securityRole.RecId
    && omUserRoleOrganization.OMInternalOrganization == omInternalOrganization.RecId
    && omUserRoleOrganization.User == userinfo1.id
    {
    Utilisateur.add(userinfo1.name);
    }

    while select userinfo1 exists join securityUserRole where securityUserRole.SecurityRole == securityRole.RecId && securityUserRole.User == userinfo1.id
    notexists join omUserRoleOrganization where omUserRoleOrganization.User == securityUserRole.user
    {
    Utilisateur.add(userinfo1.name);
    }

    }
    //select the list of user assigned to the role and not assigned to organization
    else if(Role.text() != "" && Organisation.text() == "")
    {
    while select userinfo1 exists join securityUserRole where securityUserRole.SecurityRole == securityRole.RecId
    && securityUserRole.User == userinfo1.id
    {
    Utilisateur.add(userinfo1.name);
    }
    }

  • BASMA Profile Picture
    BASMA 920 on at
    RE: How to filter data based on multiple lookup??

    thanks Rustem for your help :)

  • Suggested answer
    Rustem Galiamov Profile Picture
    Rustem Galiamov 8,072 on at
  • BASMA Profile Picture
    BASMA 920 on at
    RE: How to filter data based on multiple lookup??

    thanks Rustem,

    have you document about join tables?

  • Rustem Galiamov Profile Picture
    Rustem Galiamov 8,072 on at
    RE: How to filter data based on multiple lookup??

    I’ve updated the code in previous post.

  • Verified answer
    Rustem Galiamov Profile Picture
    Rustem Galiamov 8,072 on at
    RE: How to filter data based on multiple lookup??

    Try this:

    Utilisateur.clear();
        
    if(Role.text() != "" && Organisation.text() != "")
    {
        while select userinfo1
        exists join omUserRoleOrganization
            where omUserRoleOrganization.SecurityRole           == securityRole.RecId
               && omUserRoleOrganization.OMInternalOrganization == omInternalOrganization.RecId
               && omUserRoleOrganization.User                   == userinfo1.id
        {
            Utilisateur.add(userinfo1.name);
        }
    
        while select userinfo1
    exists join securityUserRole
    where securityUserRole.SecurityRole == securityRole.RecId
    && securityUserRole.User == userinfo1.id notexists join omUserRoleOrganization where omUserRoleOrganization.User == securityUserRole.User { Utilisateur.add(userinfo1.name); } } else if(Role.text() != "" && Organisation.text() == "") { while select userinfo1 exists join securityUserRole where securityUserRole.SecurityRole == securityRole.RecId && securityUserRole.User == userinfo1.id { Utilisateur.add(userinfo1.name); } }

    And i recommend to learn more about how to join tables.

  • BASMA Profile Picture
    BASMA 920 on at
    RE: How to filter data based on multiple lookup??

    I have this form:

    5481.user.png

    I want to display a list of user that are assigned to selected role and organization.

    for example in the selected role "A"there is a user "userA" that has access  to all organization:normally when I  select role "A"  and I select one of organisation I should get the "userA" in the list.

    now i get only the users exist in OMUsrOrgnizationRole.

    I hope that you understand me

  • Rustem Galiamov Profile Picture
    Rustem Galiamov 8,072 on at
    RE: How to filter data based on multiple lookup??

    Can you explain what you want to achieve?

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,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans