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" />)

Remove Timeline from a task view using PowerShell

If you create a new view for a SharePoint 2013 task list, you’ll get a timeline above the task items table.

Should you want to remove this timeline from the view using PowerShell, you should alter the ViewData property for the view.

Initially, this property contains the following data:

<FieldRef Name="PercentComplete" Type="StrikeThroughPercentComplete" /><FieldRef Name="DueDate" Type="TimelineDueDate" />

Simply remove the second FieldRef element from the view’s ViewData to remove the Timeline from the view:

$web = Get-SPWeb <insert web URL>
$view = $web.GetViewFromUrl(<insert view URL>
$view.ViewData = "<FieldRef Name=`"PercentComplete`" Type=`"StrikeThroughPercentComplete`" />"

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.

Create headers in the Quick Launch without links.

When you’re working with site templates in SharePoint Foundation, you might want to group the links to lists and libraries under different headings, than their type. By default, SharePoint will create a heading link “Libraries” and list the libraries under it. But when you’ve got a lot of libraries, you might want to group them under different labels.

But any header link in the quick launch requires that you specify a URL from the web application’s domain root, i.e. “/sitename”. You do not always want this, if you’re simply grouping links in the quick launch, having a link there is not always wanted, especially if you want to create a site template from the site.

An easy way to “deactivate” the link is by replacing the URL with the following JavaScript: javascript:window.goback(0)

This link will still be valid for SharePoint (it requires that you enter a URL), but won’t cause any navigation to happen for the user.