Thursday, October 18, 2012

Modify DataView XSLT to Add Url in Grid to Workflow Initiation Form

I recently created a data view. I wanted a simple link to the list items workflow initiation form, to simply allow the user to access and start the workflow.

The confusing aspect of all this is that normally we could do something simple such as

<a href=http://someurl/page.aspx?ID={@ID}></a>

The xsl transform will resolve {@ID} to the value of @ID.

The problem with this was that I actually also needed to include ListID and TemplateID both of these query parameters require the Guid to be wrapped in curly braces. So I modified the above and added a ListID to create the following:

<a href=http://someurl/page.aspx?ID={@ID}&List={05cf277f-5d2e-4b46-8dc9-27a1e1c5ff36}></a>

The first I problem I had with this was an error occured due to the & ampersand. I needed to encode it to and to prevent Sharepoint from erroring as a result of unencoded text.

The second problem is that curly braces resolve variables. So the second error was relating to Sharepoint failing to resolve the GUID. Which I didn't want to occur I wanted it to be taken as literal text. To escape the curly braces I imagined \{ would be the fix but instead as it turns out it's {{.

Great, I found out how to escape the curly brace....When executing the page it worked BUT it also encoded the curly brace (I didn't tell it to do this, it did it automatically) and printed %7B in the url! Not what I needed and Sharepoint wouldn't process that as a curly brace in the query string either.

So to cut a long story short the following does exactly what I want. It reads the parameter value of the datasource and escapes the curly braces


The following is a fair step away from a simple url with some encoding and escaped characters. But it works!

We still have an anchor but we assign the value via XSLT. The xsl transform for attribute allows us to append the resulting (resolved) inner block to the href attribute value. So following through I needed a couple more transforms before it became str1 + str2.

In order to properly escape the curly braces I needed to wrap the static text in an xsl:text block. Then I called for an xsl:value-of to get the ID.

   <xsl:attribute name="href">
      <xsl:text disable-output-escaping="no">http://website/_layouts/IniWrkflIP.aspx?List={05cf277f-5d2e-4b46-8dc9-27a1e1c5ff36}&amp;TemplateID={7aabfd9c-9a82-4a12-a82a-ad74cb0029c7}&amp;Source=http://teamsource/OperationalRisk/SitePages/Admin Home.aspx&amp;ID=</xsl:text>
      <xsl:value-of select="@ID"></xsl:value-of>
<img alt="reassign" style="border-width:0px;" src="http://website/_layouts/images/edititem.gif"></img></a>

Finally, I added an image to represent the button and all done!

No comments:

Post a Comment