# Fetching User Details using X++ Code

**URL:** <https://www.dynamicsuser.net/t/fetching-user-details-using-x-code/63632>\
**Category:** Developer Forum\
**Created:** [June 13, 2017, 5:51am UTC](https://www.dynamicsuser.net/t/fetching-user-details-using-x-code/63632 "2017-06-13T05:51:39Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![SarathKumar](https://avatars.discourse-cdn.com/v4/letter/s/bbe5ce/32.png) [@SarathKumar](https://www.dynamicsuser.net/u/SarathKumar)\
**Post date:** [June 13, 2017, 5:51am UTC](https://www.dynamicsuser.net/t/fetching-user-details-using-x-code/63632/1 "2017-06-13T05:51:39Z")

</div>

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 ??

---

<div class="post-metadata">

**Author:** ![MartinDrab](https://avatars.discourse-cdn.com/v4/letter/m/e0b2c6/32.png) [@MartinDrab](https://www.dynamicsuser.net/u/MartinDrab)\
**Post date:** [June 13, 2017, 6:34am UTC](https://www.dynamicsuser.net/t/fetching-user-details-using-x-code/63632/2 "2017-06-13T06:34:04Z")

</div>

You can use [UserPrincipal class](https://msdn.microsoft.com/en-us/library/system.directoryservices.accountmanagement.userprincipal(v=vs.110).aspx) via .NET Interop.

---

<div class="post-metadata">

**Author:** ![SarathKumar](https://avatars.discourse-cdn.com/v4/letter/s/bbe5ce/32.png) [@SarathKumar](https://www.dynamicsuser.net/u/SarathKumar)\
**Post date:** [June 13, 2017, 6:42am UTC](https://www.dynamicsuser.net/t/fetching-user-details-using-x-code/63632/3 "2017-06-13T06:42:45Z")

</div>

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

Thanks in advance

---

<div class="post-metadata">

**Author:** ![MartinDrab](https://avatars.discourse-cdn.com/v4/letter/m/e0b2c6/32.png) [@MartinDrab](https://www.dynamicsuser.net/u/MartinDrab)\
**Post date:** [June 13, 2017, 6:51am UTC](https://www.dynamicsuser.net/t/fetching-user-details-using-x-code/63632/4 "2017-06-13T06:51:15Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![SarathKumar](https://avatars.discourse-cdn.com/v4/letter/s/bbe5ce/32.png) [@SarathKumar](https://www.dynamicsuser.net/u/SarathKumar)\
**Post date:** [June 13, 2017, 7:07am UTC](https://www.dynamicsuser.net/t/fetching-user-details-using-x-code/63632/5 "2017-06-13T07:07:48Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![MartinDrab](https://avatars.discourse-cdn.com/v4/letter/m/e0b2c6/32.png) [@MartinDrab](https://www.dynamicsuser.net/u/MartinDrab)\
**Post date:** [June 13, 2017, 7:18am UTC](https://www.dynamicsuser.net/t/fetching-user-details-using-x-code/63632/6 "2017-06-13T07:18:36Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kranthi](https://avatars.discourse-cdn.com/v4/letter/k/e480ec/32.png) [@kranthi](https://www.dynamicsuser.net/u/kranthi)\
**Post date:** [June 13, 2017, 7:48am UTC](https://www.dynamicsuser.net/t/fetching-user-details-using-x-code/63632/7 "2017-06-13T07:48:34Z")

</div>

> [@](#):
>
> dbo.UserInfo using x++ coding in ax 2012 ??

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

---

<div class="post-metadata">

**Author:** ![SarathKumar](https://avatars.discourse-cdn.com/v4/letter/s/bbe5ce/32.png) [@SarathKumar](https://www.dynamicsuser.net/u/SarathKumar)\
**Post date:** [June 13, 2017, 8:02am UTC](https://www.dynamicsuser.net/t/fetching-user-details-using-x-code/63632/8 "2017-06-13T08:02:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kranthi](https://avatars.discourse-cdn.com/v4/letter/k/e480ec/32.png) [@kranthi](https://www.dynamicsuser.net/u/kranthi)\
**Post date:** [June 13, 2017, 8:09am UTC](https://www.dynamicsuser.net/t/fetching-user-details-using-x-code/63632/9 "2017-06-13T08:09:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![SarathKumar](https://avatars.discourse-cdn.com/v4/letter/s/bbe5ce/32.png) [@SarathKumar](https://www.dynamicsuser.net/u/SarathKumar)\
**Post date:** [June 13, 2017, 8:22am UTC](https://www.dynamicsuser.net/t/fetching-user-details-using-x-code/63632/10 "2017-06-13T08:22:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kranthi](https://avatars.discourse-cdn.com/v4/letter/k/e480ec/32.png) [@kranthi](https://www.dynamicsuser.net/u/kranthi)\
**Post date:** [June 13, 2017, 8:23am UTC](https://www.dynamicsuser.net/t/fetching-user-details-using-x-code/63632/11 "2017-06-13T08:23:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kranthi](https://avatars.discourse-cdn.com/v4/letter/k/e480ec/32.png) [@kranthi](https://www.dynamicsuser.net/u/kranthi)\
**Post date:** [June 13, 2017, 8:27am UTC](https://www.dynamicsuser.net/t/fetching-user-details-using-x-code/63632/12 "2017-06-13T08:27:59Z")

</div>

\Data Dictionary\Tables\DirPersonUser\Methods\worker

---

<div class="post-metadata">

**Author:** ![SarathKumar](https://avatars.discourse-cdn.com/v4/letter/s/bbe5ce/32.png) [@SarathKumar](https://www.dynamicsuser.net/u/SarathKumar)\
**Post date:** [June 13, 2017, 8:46am UTC](https://www.dynamicsuser.net/t/fetching-user-details-using-x-code/63632/13 "2017-06-13T08:46:05Z")

</div>

thanku kranthi found the solution and all fields are retrieving correctly

---

<div class="post-metadata">

**Author:** ![Sanshe46](https://avatars.discourse-cdn.com/v4/letter/s/8dc957/32.png) [@Sanshe46](https://www.dynamicsuser.net/u/Sanshe46)\
**Post date:** [June 13, 2017, 8:47am UTC](https://www.dynamicsuser.net/t/fetching-user-details-using-x-code/63632/14 "2017-06-13T08:47:25Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![MartinDrab](https://avatars.discourse-cdn.com/v4/letter/m/e0b2c6/32.png) [@MartinDrab](https://www.dynamicsuser.net/u/MartinDrab)\
**Post date:** [June 13, 2017, 10:17am UTC](https://www.dynamicsuser.net/t/fetching-user-details-using-x-code/63632/15 "2017-06-13T10:17:02Z")

</div>

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