0

I posted this question on StackOverflow a couple of weeks ago, but since it hasn't got very much attention I'm posting it here instead.


I'm building a Content Query Web Part that is supposed to show a link to a user page (userdisp.aspx). I get the user name from a custom list containing a column named 'Member' of the type 'Person or Group'.

enter image description here

To build the link in the ItemStyle.xsl, I need both the name and the Id of the user:

<a href="http://<site>/_layouts/userdisp.aspx?ID=@ID">
    <xsl:value-of select="@Name" />
</a>

However, I'm only able to get the name OR the Id from the Content Query. E.g. if I set "Show field: Name (with presence)" for the Member column I get the name, and if I set "Show field: ID" I obviously get the Id. But I need both!

enter image description here

enter image description here

I should probably also point out that I'm building the solution on a very stripped down version of SharePoint, so all I have to play with is .xsl and .webpart files, and whichever settings I can make in the online editor (no access to SharePoint Designer).

Last but not least, my SharePoint knowledge level is noob. :)

1
  • I know this is an older post. But I still have this problem. I would like to add additional fields of the field person (ID, name, workphone, email) to CQWP. I can't find a solution. Are there any alternative workarounds. Also in the list one can not over Lookup or Calculated to the Infos come. Looking forward to your answers. Mar 31, 2017 at 9:17

4 Answers 4

1

Technically the People Picker column values are a span with a BUNCH of attributes stuck to it. Here is normally how I get the two main basics from it:

ID => <xsl:value-of select="substring-before(substring-after(@PickerColumn, 'ID='), '&amp;')" />

Display Name => <xsl:value-of select="substring-before(substring-after(@PickerColumn, '&gt;'), '&lt;')" />

Haven't used the last one in a while so let me know if it doesn't work. Hope that helps!

3
  • Well, that's what I thought too, but it seems that when passing the column to a Content Query web part, you can only get one (1) of the attributes. When I do the same thing for a Link type column, I'm able to get comma separated attributes: URL = http://google.com, Google Search
    – spacedoom
    Jun 26, 2014 at 6:00
  • I've added an image to the question, showing the "Show field" selection that affects which attribute is sent to the content query. I'd like an "All attributes as comma separated values" option! :)
    – spacedoom
    Jun 26, 2014 at 6:10
  • Just tried the Display Name expression above on SP 2016 (on premises) and it does not return anything. Nov 27, 2018 at 17:59
1

I found a solution that works for me. I doesn't solve the original problem (getting both Name and ID) - it proposes another solution.

Instead of trying to get both Name and ID (I thought I needed the ID to build the URL to the member's page), I used the following to look up the URL of the member:

<xsl:variable name="SafeLinkUrl">
    <xsl:call-template name="OuterTemplate.GetSafeLink">
        <xsl:with-param name="UrlColumnName" select="'LinkUrl'"/>
    </xsl:call-template>
</xsl:variable>

So instead of this:

<a href="http://<my_site>/sites/<my_sub_site>/_layouts/userdisp.aspx?ID={@ID}">
    <xsl:value-of select="@Member" />
</a>

I ended up with this

<a href="{$SafeLinkUrl}">
    <xsl:value-of select="@Member" />
</a>

in the itemstyle.xsl. Much cleaner - and it works! :)

0

this worked for me :

<xsl:value-of select="@PersonColum.title" />      ----- for Name 
<xsl:value-of select="@PersonColum.id" />         ----- for id
0

I would add this as a comment to @T0t3sMcG0t3s post but don’t have enough rep. Here is the XSLT I used to get the display name of the group or person field.

substring-before(substring-after(substring-after(@AssignedTo, 'GoToLinkOrDialogNewWindow(this)'),'&gt;'),'&lt;')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.