Wednesday, April 29, 2009

Using XSLT to Create a Forms Server Link on a Task Form

When you use the "Assign a To-do Item" action in a SharePoint Designer workflow, a form is created that is presented to the user when they edit the task that the action created. This form allows the user to "complete the task" that was assigned during the workflow.

Located on this task form is a link to the related list item. When this related list item is an InfoPath form, a link is provided to the xml form, but unfortunately this link doesn't respect the "open in browser" directive that is selected on the form library advanced settings when the library is configured to forms server. Here's how you can make a change to the XSLT on the form to change the link to open the form using forms server.


First, open the aspx form that was created in the SPD workflow. You're going to edit some of the form code. Go ahead the click the Split tab at the bottom to view the code and the form design.


Once the form is open, click on the chevron to open the Common Data View Tasks pane. If you can't get to the chevron, you can right-click on PlaceHolderMain and select Show Common Control Tasks. Check the box "Show with sample data." This will display the table as shown.


While in the split mode, click to place your cursor in the cell to the right of the cell containing the label "Related list item." It's the one that looks empty. Notice in the code window where your cursor is located. Find the <a> tag and all its related code. It should be similar to that shown.

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

Now, change the code between the quotes in the href= as follows. Of course, you need to use your relative URL to the formserver.aspx page.

{concat('http://portal.awbikes.local/st/_layouts/formserver.aspx?XmlLocation=',substring-before(@WorkflowLink,', '),'&amp;OpenIn=Browser')}

You are using the concat function to create a link to the form server as described in MSDN at http://msdn.microsoft.com/en-us/library/ms772417.aspx. In this instance, the link will look like this:

http://portal.awbikes.local/st/_layouts/formserver.aspx?XmlLocation=URL-TO-XML-FORM&OpenIn=Browser

Now, when you click on the link you should see the form opens with forms services.



Subsequent recompiles of the workflow will not affect your form modifications. If you make a mistake and need to start over, simply delete the aspx task form and recompile your workflow.

2 comments:

.NET Dev said...

See here for generalize and easy solution to invoke browser enabled form. No need to use concat function.

Russell Wright said...

Great (and simpler) solution! Thanks for the feedback.