Form Services and SPD Workflows…

Send to Kindle

For those of you who are developers and have to program XSL and XSLT, you have my deepest sympathies. I thought that regular expressions were bad, but this takes the cake! Despite my best efforts as a SharePoint architect/consultant, I seem to invariably have to deal with programming issues more often than I’d like.

In saying that though, XSL/XSLT is very powerful of course and I fully appreciate why the Data View web part is popular among developers. Anyway, I digress. This post is about forms services and SharePoint Designer workflow, but I had to dabble into this world to solve my problem. A word of warning though, this is a workaround but it’s not that clever.

The Symptom

You create a SharePoint designer workflow and attach it to a forms library, configured to run in forms server mode (in the browser). You create a “Collect Data From a User” workflow action, and when the workflow recipient clicks on the task, the “Related list item” field in the task is not rendered in the browser.

Below is a sample of the form being rendered correctly when being filled in and then not being rendered correctly when it is accessed via editing the associated “Collect data from a user” task.

image  image

The Problem

The ‘related list item’ link always references the original list/library and item that the workflow was triggered from. It has no idea that this is a URL rendered via forms services. The default URL for the above example when referred to as an item in a form library is


Yet when rendered within forms server, the URL is:


So, the problem is that the wrong URL is being passed into the task item as the ‘related list item’. Forms services is never referred to.

The Workaround

Modify the task ASPX page (specifically XSLT code) created by the workflow to reference the forms server version of the related list item URL. This involves some modifications to XML/XSLT to achieve and we have to deal with the encoding of spaces and potentially other characters.

Problem Details

The issue is related to the way the “Collect Data From a User” workflow action was written. This is one of three built in SPD workflow actions that create a task entry. This workflow action works by creating a custom task form. The custom task form is the ASPX file that is presented to the user when they view or edit their task. Being a custom ASPX file, it can be customised to with additional form fields as you see fit. Below is an example of constructing such a task action.

Creating the workflow

Start SharePoint Designer and open the site in question. From the file menu, choose New and Workflow from the list and assign it to your infopath form library.


Create a “Collect Data from a User” action and give the task a name in the custom task wizard.

clip_image002[1]  clip_image002[3]

Click NEXT and then add any custom fields that you want the user to fill in as shown below.

image  image

Now set the person to assign the task to and you are ready to go!


Testing the workflow

So now we fill in a form and test the workflow that a task has been created. As you can see on the next two screens, the workflow is in progress once the form has been filled out.


If we examine the task list, we can see the task created by the workflow action.


Clicking EDIT item and we see the custom task form that I described in the previous section with the ‘related list item’ link.


Clicking the ‘related list item’ ideally would re-load the form via forms server, but instead, because the URL is wrong it loads the Infopath client or prompts you to choose an application to open the file with.


Before I detail the steps to working around this problem, let’s have a quick interlude on how the custom task form is done.

Theory Interlude…

(If the theory doesn’t concern you, skip to the next section entitled “The Fix #1”).

In Office SharePoint Designer 2007, when you create a ‘collect data from user’ task, it creates a custom task form in the form of an ASPX file. This appears in the folder for that workflow. The file name of the custom task form corresponds to the name that you give the task in the Custom Form Wizard.


Inside this ASPX file is a Data View Web Part in form (read/write) mode. (As a result, it is also referred to as the data form web part). Additionally, unlike when separate ASPX pages are created for creating, editing, and viewing list or library details, this custom ASPX page contains all of this logic in the one file. How does it manage to do this? The answer is the Data Form web-part and XSL combined.

If we open up this ASPX file, we see the following structure (snipped and reordered for readability) .

First up is the definition of the DataForm WebPart. A Dataform webpart operates on data sources and those datasources (<DataSources> section) can be controlled via parameters (<Parameterbinding> section).

<WebPartPages:DataFormWebPart runat="server" IsIncluded="True" FrameType="None" NoDefaultStyle="TRUE" ViewFlag="0" Title="{974032E5-108E-419B-AECE-881778387B8B}" __markuptype="vsattributemarkup" __WebPartId="{633C30DC-0989-4D2B-95BD-C4090132D106}" id="TaskForm" pagesize="1">
[snip datasource code and parameterbindings]

Inside the DataForm webpart we have our XSL/XSLT code that controls how the data renders on the page. Again I have stripped much of the code to best explain the logic. In the code below, we have a number of xsl:template XSLT elements. This element contains rules to apply when a specified node is matched. The match attribute is used to associate the template with an XML element. The match attribute can also be used to define a template for a whole branch of the XML document (i.e. match=”/” defines the whole document).

The rule here is to call another xsl:template called “dvt_1”. The template called “dvt_1” then calls the “dvr_1.header”, “dvt_1.body” and dvt_1.commandfooter” elements and passes parameters to those elements so that the display is rendered dynamically based on the values in the datasource.

<xsl:template match="/" xmlns:x="" xmlns:dsp="" xmlns:asp="" xmlns:__designer="" xmlns:SharePoint="Microsoft.SharePoint.WebControls"> 
<xsl:call-template name="dvt_1"/>
<xsl:template name="dvt_1">
<xsl:call-template name="dvt_1.header">
<xsl:call-template name="dvt_1.body">
<xsl:call-template name="dvt_1.commandfooter">

If you examine the code you will see examples of HTML and XML combined. A full description of XSL/XSLT and related concetps like XPath is way beyond the scope of this post, but the only template that I will draw your attention to is this one below: “dvt_1.rowedit”. This is the section of code that sets the URL of the ‘related list item’.

<xsl:template name="dvt_1.rowedit"> 
<xsl:param name="Pos" />
<table border="0" cellspacing="0" width="100%">
<td class="ms-formlabel" valign="top" nowrap="true" width="25%"><b>Title:</b>
<td class="ms-formbody" valign="top" width="75%">Just do it you weenie!<br></br><br></br>
[snip some other table rows]
<td class="ms-formlabel" valign="top" nowrap="true" width="25%"><b>Related list item:</b>
<td class="ms-formbody" valign="top" width="75%"><a href="{substring-before(@WorkflowLink, ', ')}"><xsl:value-of select="substring-after(@WorkflowLink, ', ')"></xsl:value-of></a>
[snip the rest]

So, now we have found the area we need to modify, let’s go back to the work!

The Fix #1

So to recap, we need to turn this:


into this:


The line of code that generates the URL is this:

<a href="{substring-before(@WorkflowLink, ', ')}">
<xsl:value-of select="substring-after(@WorkflowLink, ', ')"></xsl:value-of>

@WorkflowLink is a variable that returns the path to the related list item in the format:

<full url path>, <file name>



So if you look carefully at the code above, it uses the text to the left of the comma separator to create the hyperlink using the {substring-after(@WorkflowLink, ‘,’) code. It then uses the text to the right of the comma to create the link display using the <xsl:value-of select=”substring-after(@WorkflowLink, ‘, ‘) code.

So my first attempt at a fix was to change the code to hard-code the forms server URL like this:

<a href="http://tidemo/tftp/_layouts/FormServer.aspx?XmlLocation=/Forms/{substring-after(@WorkflowLink, ', ')}.xml&amp;DefaultItemOpen=1">
<xsl:value-of select="substring-after(@WorkflowLink, ', ')"></xsl:value-of>

The only thing to note here is that I had to encode the & in &DefaultitemOpen=1 to &amp; so that XML parser didn’t get upset at me. So we click the ‘related list item’ link now and then see that the infopath form renders in the browser (Yay!)

image image

I then encountered a problem. As soon as I used a space in the name of the form as the example below shows, bad things happened.

image image

The Fix #2

The above problem is caused by the fact that the space makes forms server unhappy. So what if we try changing all occurrences of spaces in a name to its %20 equivalent?

No problem in theory, but string manipulation using XSL is… shall we say… ugly. Maybe there is a better way, but the method I found was this:

We have to pass @WorkFlowLink variable to our own custom xsl:template as shown below and then pass it the string to search and replace (in this case encoding a space ‘ ‘).

<xsl:variable name="myString" select="substring-after(@WorkflowLink, ', ')"/> 
<xsl:variable name="myNewString">
<xsl:call-template name="replaceCharsInString">
<xsl:with-param name="stringIn" select="string($myString)"/>
<xsl:with-param name="charsIn" select="' '"/>
<xsl:with-param name="charsOut" select="'%20'"/>
<xsl:variable name="myNewRealString" select="string($myNewString)"/>

So the above section shows code that needs to be pasted into the source code BEFORE the reference to @Workflow.

<a href="{substring-before(@WorkflowLink, ', ')}">
<xsl:value-of select="substring-after(@WorkflowLink, ', ')"></xsl:value-of>

Here is the template that actually does the string substitution from here .

<xsl:template name="replaceCharsInString"> 
<xsl:param name="stringIn"/>
<xsl:param name="charsIn"/>
<xsl:param name="charsOut"/>
<xsl:when test="contains($stringIn,$charsIn)">
<xsl:value-of select="concat(substring-before($stringIn,$charsIn),$charsOut)"/>
<xsl:call-template name="replaceCharsInString">
<xsl:with-param name="stringIn" select="substring-after($stringIn,$charsIn)"/>
<xsl:with-param name="charsIn" select="$charsIn"/>
<xsl:with-param name="charsOut" select="$charsOut"/>
<xsl:value-of select="$stringIn"/>

So finally, we have the above 2 sections of code pasted into the custom form and then we can modify the HTML from this:

<a href="{substring-before(@WorkflowLink, ', ')}">
<xsl:value-of select="substring-after(@WorkflowLink, ', ')"></xsl:value-of>

To this:

<a href="http://tidemo/tftp/_layouts/FormServer.aspx?XmlLocation=/Forms/{$myNewRealString}.xml&amp;DefaultItemOpen=1">
<xsl:value-of select="substring-after(@WorkflowLink, ', ')"></xsl:value-of>

So assuming that the $myNewRealString variable exists and uses this as the URL instead. This time the form rendered fine 🙂

It still sucks

Why does this suck? Oh, so many reasons!

First up, I am hardcoding aspects of the URL and hardcoding is bad! I am sure that with more XSL manipulation I could easily pull that from another variable and create the URL I need. Although it is uncool, it is not beyond hope. As a quick and dirty workaround, it has its uses I guess.

The second is that we have more than a space to potentially encode. Other characters often encoded are:

Dollar (“$”)
Ampersand (“&”)
Plus (“+”)
Comma (“,”)
Forward slash/Virgule (“/”)
Colon (“:”)

So depending on the naming convention for forms, we may have to have repeated sections of code calling replaceCharsInString with the character and encoded version.

Even that is not the clincher.

According to Microsoft, the custom task form can be customized for layout and appearance only. You can attach a different master page or modify the styles. However, to change what fields appear on the form, you must use the Custom Task Wizard in the Workflow Designer. You cannot change the form fields by editing the Data Form Web Part directly. If you make other customizations to the Data Form Web Part, those changes are lost each time the workflow is recompiled.

Ouch! I did actually know that, but it just means this method introduces a governance layer of additional tasks to perform during change control/configuration management. The customisations would have to be reapplied each time the workflow is republished.

CleverWorkArounds Rating: Why did I bother?

Less Sucky?

The least sucky way to do this is to create your own workflow action, rather than use the existing ones. If I have time I will investigate this method where rather than write my own custom action, I would use the technique of handlers to modify the behaviour of the “collect data from a user” activity.

Robert Bodge has written about the clever way to do it here: ( This is a much better method, however you will have to do some work yourself. He gives you the basics on what to do and code, but leaves you to get it compiled and working yourself. If I have time and inclination I’ll give it a go. Thanks Robert!


Do I have a moral to this story? Not really, but hopefully at least we all have learnt something 🙂

Print Friendly, PDF & Email
 Digg  Facebook  StumbleUpon  Technorati  Slashdot  Twitter  Sphinn  Mixx  Google  DZone 

No Tags

Send to Kindle
Bookmark the permalink.

10 Responses to Form Services and SPD Workflows…

  1. Pingback: CleverWorkarounds » More SharePoint Branding - customisation using Javascript - Part 1

  2. Den says:

    life saver! thx!

  3. Pingback: Problema con Infopath webform y el Workflow Task Form | hilpers

  4. Cass says:

    Great tutorial! Worked perfectly in my situation and solved my problem. Thanks!

  5. urenjoy says:

    Simple,Precise and generalize solution for this is to set querystring parameter.
    See following for more detail:

  6. admin says:

    Terrific solution urenjoy. Nice work

  7. Josh says:

    What happens if you just append the link with ?OpenIn=Browser

  8. Pingback: CleverWorkarounds » Sack Justin Bieber with SPD2010 and Forms Services – Part 1

  9. Jeff says:

    Is it possible to use one field in a CollectDataFromAUser.aspx page to control the visibility of another field? For example, I want to have a Yes/No dropdown control whether or not a subsequent field is displayed. If yes, that field gets hidden. If no, that field is visible.

  10. eportfolio says:

    It is best to create a new workflow action rather than using the old one!

Leave a Reply

Your email address will not be published. Required fields are marked *