giovedì, aprile 08, 2010

SharePoint Designer and Grouping on Name Fields

A surprisingly vexing bug in SharePoint Designer 2007 is grouping by a name field, such as “created by” or “modified by.” Frequently, you will observe multiple groups occuring for a single user. Reason: each name field has a link that contains a distinct numerical value. This causes SharePoint Designer to treat each name as a separate value to group by. In the code view, look for the highlighted item below.

<nobr><span><A HREF="/yoursite/_layouts/userdisp.aspx?ID=92">User Name</A><img border="0" height="1" width="3" src="/_layouts/images/blank.gif"/><a href='javascript:' onclick='IMNImageOnClick();return false;' class='ms-imnlink'><img name='imnmark' title='' border='0' height='12' width='12' src='/_layouts/images/blank.gif' alt='No presence information' sip='uname@yourdomain.com' id='imn_4799,type=sip'/></a></span></nobr>

The solution is to modify the XSL to look only at the value of the name field, and pull out the value of the hyperlink that points to the user's details. Dipesh's Blog offers this nice XSL example:

<xsl:choose>
<xsl:when test=”not ($dvt_groupfield)”><xsl:value-of select=”ddwrt:NameChanged(string(@Name), 0)” /></xsl:when>
 <xsl:otherwise></xsl:otherwise>
</xsl:choose>

Change this value to:

<xsl:choose>
 <xsl:when test=”not ($dvt_groupfield)”><xsl:value-of select=”ddwrt:NameChanged(string(substring-before(@Name,’&lt;/A&gt;’)), 0)” /></xsl:when>
 <xsl:otherwise></xsl:otherwise>
</xsl:choose>

There is also a nice example on social.msdn.microsoft.com. Hopefully Microsoft will fix this in SharePoint Designer 2010?