How to get user details (Phone, Position, etc) for macro in Confluence?
Asked by Tsol:

Hi everybody,

Starting from the last [succefull login macro](http://blog.networkedcollaboration.com/2012/02/11/confluence-last-login-user-macro/) from Andrew Frayling and from the [macro that produces a list of users last login date](/questions/33385/macro-that-produces-a-list-of-users-last-login-date) from Remo Siegwart i want to create a macro that will also take personal details from every user like Phone, Position etc in order to create a report.

Any idea how i can take the personal details?

Thanks in advance,

Kostas


Answers:
author: Andreas Gounaris
body: I think I have an answer for you, not sure if this is the quickest route but it does the job.

Use your findings in [macro that produces a list of users last login date](/questions/33385/macro-that-produces-a-list-of-users-last-login-date) and get another component:

```
#set($userDetailsManager = $containerContext.getComponent('userDetailsManager'))
```

You print user details like this:

```
$userDetailsManager.getStringProperty($action.remoteUser, 'location')
```

You can even get them by group and iterate using:

```
$userDetailsManager.getProfileGroups();$userDetailsManager.getProfileKeys($group);
```

And lastly, you could load a wiki markup renderer for personal information (about me) user field. This thing was a real pain for me. Check out my findings:

[https://answers.atlassian.com/questions/98010/how-do-i-get-the-about-me-field-from-a-confluence-user-macro](/questions/98010/how-do-i-get-the-about-me-field-from-a-confluence-user-macro)

it worked !! :)

comments: author: Tsol
body: Hey Andreas,

Thanx for your help.

I'm getting the component below

```
#set($userDetailsManager = $containerContext.getComponent('userDetailsManager'))
```

but i don't know how to print user details for all users.

The macro that i have is:

```
#set($userDetailsManager = $containerContext.getComponent('userDetailsManager')) #set($loginManager = $containerContext.getComponent('loginManager'))#set($group = $userAccessor.getGroup($paramgroup))#if($group)    #set($usernames = $userAccessor.getMemberNames($group))     &lt;table class="confluenceTable"&gt;        &lt;tr&gt;			&lt;th class="confluenceTh"&gt;Count&lt;/th&gt;            &lt;th class="confluenceTh"&gt;User&lt;/th&gt;			&lt;th class="confluenceTh"&gt;Tel&lt;/th&gt;			&lt;th class="confluenceTh"&gt;Groups&lt;/th&gt;            &lt;th class="confluenceTh"&gt;Last Successful Login Date&lt;/th&gt;        &lt;/tr&gt;			#set($count = 0)			#foreach($username in $usernames)            #set($user = $userAccessor.getUser($username))			#set($groups = $userAccessor.getGroupNamesForUserName($user.name))			        &lt;tr&gt;			#set($count = $count + 1)			&lt;td class="confluenceTd"&gt;$count&lt;/td&gt;			&lt;td class="confluenceTd"&gt;#usernameLink($user.name)&lt;/td&gt;			&lt;td class="confluenceTd"&gt;$userDetailsManager.getStringProperty($userAccessor.getUser($username)), 'location')&lt;/td&gt;			&lt;td class="confluenceTd"&gt;$groups&lt;/td&gt;			&lt;td class="confluenceTd"&gt;$action.dateFormatter.formatDateTime($loginManager.getLoginInfo($user).lastSuccessfulLoginDate)&lt;/td&gt;        &lt;/tr&gt;			#end    &lt;/table&gt;#else    &lt;p&gt;&lt;i&gt;No group with name "$paramgroup" found!&lt;/i&gt;&lt;/p&gt;#end
```

If i use

```
$userDetailsManager.getStringProperty($userAccessor.getUser($username)), 'location')
?
```

doesn't print anything.

If i use

```
$userDetailsManager.getStringProperty($action.remoteUser, 'location')
```

prints the location of currently logged in user for every use.

I have use various combinations without success.

Any idea?

Thanx again for the help patrioti :)

Cheers,

Kostas


author: Tsol
body: Andreas i've pressed on i don't like this post by mistake. I'm trying to undo the action and i have a warning that an error occurs. I'll try to undo it.

I found the solution with your help.

Cheers,

Kostas


author: Andreas Gounaris
body: Haven't tried to iterate user objects, some suggestions:

Does your loop works? Where do you place the line to get the user's property? If you have the $user, try using it to get its properties, instead of userAccessor.getUser().

Andreas


author: Tsol
body: Hey andreas,

Macros work fine. The down vote was by mistake.

The problem with undo down vote is not resolved yet. I have raised an issue to atlassian

<https://jira.atlassian.com/browse/ANSWERS-818>.

Kala Christougenna,

Kostas


author: Andreas Gounaris
body: No worries Kosta,

Merry Xmas kai KALH XRONIA - Happy new year !!

Andreas


author: Andreas Gounaris
body: I have the same issue patrioti, need to get the "About Me" field from the user.

David said the trick is to get to the **UserDetailsManager** object, *which is not one of the [Confluence Objects Accessible From Velocity](https://developer.atlassian.com/display/CONFDEV/Confluence+Objects+Accessible+From+Velocity).* (David says)

Check out his answers in the cases below, a bit tricky, need to have confuence source, eclipse or some other IDE - and go figure.

My problem is with velocity, you can get the userAccessor but then, what route do you follow to get to the userDetailsManager :  
$action.getUserAccessor()..?... getEditMyProfileAction().getUserDetailsMap().getProperty('website')

Something like this maybe:  
$action.getUserAccessor().getUserPreferences($action.remoteUser).getString('website')

.. doesn't work either :/

Maybe, you can get something out of his comments and share it with us

**Case 1:** [https://answers.atlassian.com/questions/98010/how-do-i-get-the-about-me-field-from-a-confluence-user-macro](/questions/98010/how-do-i-get-the-about-me-field-from-a-confluence-user-macro)

**Case 2:** [https://answers.atlassian.com/questions/11686/can-i-pull-a-specific-value-out-of-a-user-s-profile-for-use-in-another-macro](/questions/11686/can-i-pull-a-specific-value-out-of-a-user-s-profile-for-use-in-another-macro)

<br />

<br />


author: Stefan Kleineikenscheidt _K15t_
body: Check out the following two managers:

\* com.atlassian.confluence.user.PersonalInformationManager  
\* com.atlassian.confluence.user.UserDetailsManager

Cheers,  
-Stefan


author: Matthew J. Horn
body: Unless you can access the client through a mobile API, I don't think you can get the position (I assume you mean the GPS coordinates of the requesting device) from Confluence. You could use an analytics tool to give you general location-based information about clients, such as country of origin.

As for "Phone", I assume you mean the type of client device used to access the page. You can use JavaScript to get the clienty type (which would be the browser, which would hint at the phone type), but I don't think you can get the type of phone, again, without accessing a mobile API.

comments: author: Stefan Kleineikenscheidt _K15t_
body: I think he means the user details stored in the confluence user profile.


author: Tsol
body: Yeap. Maybe i didn't make it so clear but i need the details of user profile.


Tags: user-macro