Fetching User Details using X++ Code

Hi All,

how to fetch the details such as name,title, department name,group names, domain of users and groups of Active directory that are configured in table dbo.UserInfo using x++ coding in ax 2012 ??

You can use UserPrincipal class via .NET Interop.

Can you pls explain with the x++ code if possible which will be very useful for me.

Thanks in advance

What exactly do you want me to demonstrate? Where did you get stuck when you tried it by yourself before giving up?
Do you need some introduction to .NET Interop, you don’t know how to create the object or what?

I am stuck in retrieving the department for the active directory users

And specifically? Do you already have an instance of UserPrincipal representing the user?

Why cannot you get the details from that table? Am i missing something?

it does not contains few details like department, group assgined to users, title for users and company names so I need relation with other tables to fetch I am facing difficult to fetch department name and users titles for active directory users. Please suggest a way if possible

I think, you should have been more specific in your original question.

You have to get the worker related to the user(user relations) and form there you need to get the department assigned to the worker.
Have a look at HCMWorker.getPrimaryDepartment();

For title,

\Data Dictionary\Tables\HcmWorker\Methods\title

Can u suugest the relation between UserInfo table and HcmWorker table in ax 2012?

There is a table in between, DirPersonUser - It should have methods to find worker.

\Data Dictionary\Tables\DirPersonUser\Methods\worker

thanku kranthi found the solution and all fields are retrieving correctly

recId = HcmWorker::userId2Worker(curuserid());
use the above methods to retrieve the value for departments assigned to the user.

Aha, so it wasn’t about “department name […] and groups of Active directory” at all. :slight_smile: