Compare two SharePoint person fields in XSLT using SharePoint Designer

If you want to compare two columns, a simple way would be to create a calculated column. However, SharePoint doesn’t let you use Person fields (columns) in calculated column.

With a little XSLT, you can compare two person columns in a DataFormWebPart.

Say you add an extra column to a task list, called “OriginallyAssignedTo” and you want to check if the “AssignedTo” column matches the “OriginallyAssignedTo” column.

Within the DataFormWebPart’s dvt_1 template, you add the following code:

<xsl:variable name="CurrentlyAssignedTo" select="@AssignedTo" />
<xsl:variable name="OriginallyAssignedTo" select="@OriginallyAssignedTo" />
<xsl:variable name="TaskDelegated" select=substring-before(substring-after($CurrentlyAssignedTo, 'userdisp.aspx?ID='), '"') != substring-before(substring-after($OriginallyAssignedTo, 'userdisp.aspx?ID='), '"')" />

The variable $TaskDelegated will be false if the two person fields are the same and true if they are different. Comparison is being made based on the ID parameter which is used in the /_layouts/userdisp.aspx page.

So you could show the task’s original owner if it differs from the current owner like this:

<xsl:value-of select="@AssignedTo" disable-output-escaping="yes"/>
<xsl:if test="$TaskDelegated">
	(on behalf of <xsl:value-of select="@OriginallyAssignedTo" disable-output-escaping="yes" />)

Where has the Else-If branch gone to in SharePoint Designer 2013?

In SharePoint 2010, you could create conditional trees with OR statements, like so:

IF <value> equals <value> THEN
OR IF <value> equals <value> THEN

In SharePoint 2013, this has changed. The OR condition, is now moved within the ELSE branch:

IF <value> equals <value> THEN
    IF <value> equals <value> THEN

While this makes it slightly less apealing in the Text-Based designer, it does make sense when you understand how Microsoft tries to promote Visio 2013, for designing SharePoint 2013 workflows visually, which can be done if you have Visio 2013 Professional installed on your client:

Click for bigger version

Above shows the if then else branch (without any actions) with 3 possible outcomes.

Extract the parent foldername of a document in a SharePoint Designer 2013 workflow

Using the LastIndexOf Algorithm for SharePoint 2013 workflows described in my previous post, you can now extract the parent folder of a document in a SharePoint 2013 workflow using SharePoint Designer.

The following example retrieves the parent folder for any document. The variable FolderName is empty for documents that are created in the root of the site collection. Handy for custom (drop-off) libraries that require action or routing based on the folder in which the document is placed. (Of course, normally you’d use metadata columns for this, but in some cases, columns are not really an option, i.e. when dealing with documents coming from SharePoint-unaware scanners).

Click for the full version


LastIndexOf in a SharePoint 2013 workflow using SharePoint Designer 2013

Unfortunately, there is no out-of-the-box Workflow action for String.LastIndexOf() in SharePoint 2013 workflows when working with SharePoint Designer 2013, but using the new Loop condition, you can get the last index of any character or string:

Use the following actions to retrieve the last index:

Click for a bigger version

This algorithm uses the following local variables:

This can come in handy, when you want to dissect a filename or URL in a workflow.