Tuesday, June 9, 2009

InfoPath cannot handle URL fields in SP lists

One component of the dream of no-code SharePoint is to store data in SharePoint lists and expose the data thru Infopath [which business analysts and administrators can use to change the UI design easily].

This dream is dimmed slightly when InfoPath cannot handle SharePoint list types correctly. In this case, URL fields are not parsed correctly causing the link field to fail [when clicked].

In this example, I made a URL field in a custom list called "u 0" and I stored a value in it.

Make the infoPath form with a datasource pointing to the custom list. Then you will see the symptom of this problem. The problem itself is caused by this XSLT code stored in view1.xsl. (Sorry, I could not get the formatting to work!)

<span class="xdHyperlink" hideFocus="1" title="" style="OVERFLOW: visible; WIDTH: 130px; TEXT-ALIGN: left" xd:xctname="Hyperlink">
<a class="xdDataBindingUI" xd:CtrlId="CTRL4" tabIndex="0" xd:disableEditing="yes">
<xsl:attribute name="href">
<xsl:value-of select="@u_0"/>
</xsl:attribute>
<xsl:value-of select="@u_0"/>
</a>
</span>


The correct code is shown below:


<span class="xdHyperlink" hideFocus="1" title="" style="OVERFLOW: visible; WIDTH: 130px; TEXT-ALIGN: left" xd:xctname="Hyperlink">
<a class="xdDataBindingUI" xd:CtrlId="CTRL4" tabIndex="0" xd:disableEditing="yes">
<xsl:attribute name="href">
<xsl:value-of select="substring-before(@u_0, ',')"/>
</xsl:attribute>
<xsl:value-of select="substring-after(@u_0, ',')"/>
</a>
</span>

I find it hard to believe but apparently noone has documented this out on the web. After I debugged it, I found this link from 2005 about the SPD predecessor, of which #5 & #6 are the answer.

It is also frustrating that Microsoft has not fixed this in the InfoPath 2007 product.

Regards..

1 comment:

  1. Roger,
    Great post. Thanks for the help. I tried this out and it works perfectly in an infopath form but when I try to move it to a browser based form I get the following error.

    The SOAP response indicates that an error occurred on the server.
    Server was unable to process request ----> Value cannot be null
    Parameter Name: key

    From what I can tell it is the substring-after that is erroring out in the form. Havn't had much luck finding an answer. Any help would be appreciated.

    Regards,
    Derek

    ReplyDelete