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

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

How to Identify the current user group for the current user logon to AX using X++ and populate that group on Form.

(0) ShareShare
ReportReport
Posted on by 5,248

Hi,

I need to get current logged in user group and need to populate that user group in all over the forms by placing the label or link.

i am able to get the user group with following code. please correct the following code also suggest how do i populate group, when ever user access the form i need to place link or label on each form and that will populate the current user group.

public static client void main(Args _args)
{
    UserGroupList groups;
    UserInfo userInfo;
      select * from userInfo where userInfo.id == curuserid();

    info(strfmt("You have login by this %1 user id and alias name is %2",curuserid(),userInfo.networkAlias));

    info("You belong to  following user groups");

   while select groups where groups.userId == curuserid()

    {

        info(groups.groupId);
        info(curuserid());

    }
      //info(curuserid());

}


Please Help ASAP

*This post is locked for comments

I have the same question (0)
  • Martin Dráb Profile Picture
    236,519 Most Valuable Professional on at
    RE: How to Identify the current user group for the current user logon to AX using X++ and populate that group on Form.

    You tagged the question with "AX 2012", but UserGroupList table doesn't exist in AX 2012, therefore your code wouldn't even compile. Something from what you wrote is not correct - please fix it.

    If you really can use UserGroupList, you see that the user may be assigned to many groups. If you want to use a single group ID, you need to decide which one to use.

    Where do you want to populate the group ID? If to a field, just use table.Field = groupId. If it should go to an unbound control, use something like stringControl.text(groupId).

  • Bashir Ahmad Profile Picture
    5,248 on at
    RE: How to Identify the current user group for the current user logon to AX using X++ and populate that group on Form.

    Thanks Martin,

    Yes you are right the following code is returning Null.

    following code is not working but i am not getting any compilation error.

    while select groups where groups.userId == curuserid()

    {

    info(groups.groupId);

    }

    can you please suggest the exact table name, also i am working with AX2012 R2

  • André Arnaud de Calavon Profile Picture
    299,509 Super User 2025 Season 2 on at
    RE: How to Identify the current user group for the current user logon to AX using X++ and populate that group on Form.

    Hi Bashir,

    Are you upgrading an environment from AX4 or AX2009? The security is different in AX 2012. What is the exact business requirement?

    Roles assigned to a user can be found in the table SecurityUserRole.

    The functionality for user groups is still available in AX 2012, but this is only used at Journals for approval and indicating which users are allowed to post in certain ledger periods. So the table UserGroupList does still exists, but I wonder if you need this table or another one.

  • Bashir Ahmad Profile Picture
    5,248 on at
    RE: How to Identify the current user group for the current user logon to AX using X++ and populate that group on Form.

    let me correct the question, Actually i need to get The current user Active Directory Group.

    the user belongs to group in a domain.

  • Martin Dráb Profile Picture
    236,519 Most Valuable Professional on at
    RE: How to Identify the current user group for the current user logon to AX using X++ and populate that group on Form.

    Ah, my mistake. There is no system table UserGroupList in AX 2012, as it used to exist in older versions - it's now considered deleted and it's been turned to DEL_UserGroupList table.  But there is a new application table UserGroupList (in AOT among normal tables, not system tables).

  • Suggested answer
    Martin Dráb Profile Picture
    236,519 Most Valuable Professional on at
    RE: How to Identify the current user group for the current user logon to AX using X++ and populate that group on Form.

    You won't find information about AD groups in AX database, so stop looking there. But there is a solution, of course. You can use .NET types in namespace System.DirectoryServices.AccountManagement to query Active Directory, and you can use these types in X++ through .NET Interop.

    UserPrincipal.GetAuthorizationGroups() looks like what you need.

    Let me know if you get into troubles; I work quite a lot with .NET Interop.

  • Ali Zaidi Profile Picture
    4,655 on at
    RE: How to Identify the current user group for the current user logon to AX using X++ and populate that group on Form.

    You have to add following code in initial method of form. UserGroupList exists in Dynamics Ax 2012 R2 Cu7. But this table did not show you active directory group of user.

    public void init()

    {

        UserGroupList groups;

       UserInfo userInfo;

        super();

         select * from userInfo where userInfo.id == curuserid();

       select groups where groups.userId == curuserid();

       if (groups !=null)

       {

       lblUserGroup.text(groups.groupId);

       }

    }

  • Bashir Ahmad Profile Picture
    5,248 on at
    RE: How to Identify the current user group for the current user logon to AX using X++ and populate that group on Form.

    Thanks Martin,

    Yes exactly i am looking for group that user is authorized in Active directory.

    can you please share any code example by using System.DirectoryServices.AccountManagement to get the AD User group in X++

    Thanks

    Bashir Ahmad

  • Bashir Ahmad Profile Picture
    5,248 on at
    RE: How to Identify the current user group for the current user logon to AX using X++ and populate that group on Form.

    Ali,

    I have tried this code as i have mentioned in question. no data return in following query.

      select * from userInfo where userInfo.id == curuserid();

      select groups where groups.userId == curuserid();

  • Verified answer
    Jonathan  Halland Profile Picture
    11,310 on at
    RE: How to Identify the current user group for the current user logon to AX using X++ and populate that group on Form.

    Hi Bashir,

    Please view this article I wrote for this exact purpose

    www.exploreax.com/.../active-directory-lookup-in-ax-2012

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Tocauer Profile Picture

Martin Tocauer 4

#2
Community Member Profile Picture

Community Member 2

#2
Nayyar Siddiqi Profile Picture

Nayyar Siddiqi 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans