Is there a macro to get a user profile attribute?

There are various attributes in the user profile, like: Location, Department, Phone. I'm wondering if anybody developed a macro to get a value of one of the attributes for a particular user. E.g. I need to put a phone number of vgleim user on a Confluence page.

2 answers

2 votes
Stephen Deutsch Community Champion Feb 13, 2015

If you're not afraid of using a user macro, you could do this to put the name and phone number of either a specific user or a group of users on a page:

## @param User:title=Username|type=username|desc=Select username to display
## @param Group:title=Group|type=string|desc=Enter group to display.
#set ( $Integer = 0 )
#set ( $userName = "" )
#set ( $userName = $paramUser )
#set ( $groupName = "" )
#set ( $groupName = $paramGroup )
#set ( $group = "" )
#set ( $user = "" )
#set ( $containerManagerClass = $content.class.forName('com.atlassian.spring.container.ContainerManager') )
#set ( $getInstanceMethod = $containerManagerClass.getDeclaredMethod('getInstance',null) )
#set ( $containerManager = $getInstanceMethod.invoke(null,null) )
#set ( $containerContext = $containerManager.containerContext )
#set ( $userDetailsManager = $containerContext.getComponent('userDetailsManager') )
#if ( $userName != "" )
  #if ( $Integer.parseInt($generalUtil.getBuildNumber()) > 4300 )
    #set ( $user = $userAccessor.getUserByName($userName) )
  #else
    #set ( $user = $userAccessor.getUser($userName) )
  #end
  #if ( $user != "" )
    #set ( $phone = $userDetailsManager.getStringProperty($user, "phone") )
    ##set ( $im = $userDetailsManager.getStringProperty($user, "im") )
    ##set ( $website = $userDetailsManager.getStringProperty($user, "website") )
    ##set ( $position = $userDetailsManager.getStringProperty($user, "position") )
    ##set ( $department = $userDetailsManager.getStringProperty($user, "department") )
    ##set ( $location = $userDetailsManager.getStringProperty($user, "location") )
    <p> #userLink($user) - $!phone </p>
  #else
    <p> User $userName not found. </p>
  #end
#elseif ( $groupName != "" )
  <p> Members in group ${groupName}: </p>
  #set ( $group = $userAccessor.getGroup($groupName) )
  #if ( $group != "" )
    #set ( $members = $userAccessor.getMemberNames($group) )
    #foreach ( $member in $members )
      #if ( $Integer.parseInt($generalUtil.getBuildNumber()) > 4300 )
        #set ( $user = $userAccessor.getUserByName($member) )
      #else
        #set ( $user = $userAccessor.getUser($member) )
      #end
      #set ( $phone = $userDetailsManager.getStringProperty($user, "phone") )
      ##set ( $im = $userDetailsManager.getStringProperty($user, "im") )
      ##set ( $website = $userDetailsManager.getStringProperty($user, "website") )
      ##set ( $position = $userDetailsManager.getStringProperty($user, "position") )
      ##set ( $department = $userDetailsManager.getStringProperty($user, "department") )
      ##set ( $location = $userDetailsManager.getStringProperty($user, "location") )
      <p> #userLink($user) - $!phone </p>
    #end
  #else
    <p> Group $groupName not found. </p>
  #end
#end

One of the options is to install Communardo User Profile plugin. It can synchronize user attributes from AD and provides a few profile macros you can use on your pages:

 https://marketplace.atlassian.com/plugins/de.communardo.confluence.plugins.userprofile

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Kesha Thillainayagam
Posted Apr 13, 2018 in Confluence

We want to hear how your non-technical teams are using Confluence!

Hi Community! Kesha (kay-sha) from the Confluence marketing team here! Can you share stories with us on how your non-technical (think Marketing, Sales, HR, legal, etc.) teams are using Confluen...

374 views 20 10
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you