SharePoint: Open InfoPath Forms from Search Results using Forms Services

When InfoPath Forms appear in search results, clicking on their links attempts to open the form using the InfoPath client, rather than using Forms Services, if you’re using the InfoPath client thats great, if not, not so great.

However you can modify the XSLT used to render the search results so that InfoPath Forms are opened using the browser (Forms Services) quite easily.

Navigate to your search results page, edit the page and modify the webpart settings for the “Search Core Results” webpart (if you have multiple Search Core Results webpart instances, you want the one which renders the results which is typically in the Bottom Zone).

In the DataView Properties section click on the XSL Editor button and copy out the XSL to your favourite XSL editor (much easier than using the UI dialog) and locate the template shown below.

<!-- This template is called for each result -->
<xsl:template match="Result">
 <xsl:variable name="id" select="id"/>
 <xsl:variable name="url" select="url"/>
 <span class="srch-Icon">
	<a href="{$ifpurl}" id="{concat('CSR_IMG_',$id)}" title="{$url}">
	  <img align="absmiddle" src="{imageurl}" border="0" alt="{imageurl/@imageurldescription}" />
 <!-- more omitted for brevity -->

The bit of interest is where the variable url is created and set to the value of the url search result element. This variable is used is multiple places within this template to provide link targets (A href and title attributes) and link text.

You can either change how the url variable is assigned or create a new variable and use this new variable in place of url where appropriate.

This might depend on a couple of issues;

  1. If you are using a Search scope which restricts results to InfoPath Forms only, you could just change how the url variable is assigned.
  2. If you want the original Url’s preserved for display purposes but to open using Forms Services you would create a new variable.
  3. If you are not using Search scopes, or your Search scope results contain InfoPath Forms and other document types, you need to update the url variable only for InfoPath Form search results.

I’ll present a couple of examples using a new variable which you can apply using a new variable or updating the existing url variable.

First, the XSL snippet below creates a URL which opens the InfoPath Form instance using Forms Services.

<xsl:variable name="myurl">
	<xsl:value-of select="sitename"/>
	<xsl:value-of select="url"/>

Second, this XSL snippet creates a URL which opens an InfoPath Form instance using Forms Services, if the search result is an InfoPath Form, otherwise it uses the original URL.

<xsl:variable name="myurl">
		<xsl:when test="contentclass='STS_ListItem_XMLForm'">
			<xsl:value-of select="sitename"/>
			<xsl:value-of select="url"/>
			<xsl:value-of select="url"/>

If you have created a new variable, the next step is to replace uses of the original url variable with your new variable.

Having done this, copy the updated XSLT to the clipboard and paste it back into the webpart, save and publish.

The ListItem ID is not present in the search results XML schema.

Interestingly the listitem ID of the search results item is not present in the result schema, least not obviously. This is of less interest for search results which contain ListItems, rather than documents etc.

The OOTB search results XML schema is shown below;

      <title>Title Value</title>
        <c0>Title</c0> Value</hithighlightedsummary>
          <c0>Title</c0> Value</HHTitle>
      <imageurl imageurldescription="Result of type: document">/_layouts/images/STS_ListItem16.gif</imageurl>

You might think that the <id> element contains the listitem ID, however this is not so, it’s simply the id value of the search results row. The <url> element (for listitems) does contain the list item ID though, as it is the URL to show the ListItem properties using the DispForm.aspx page, which has the ID= querystring parameter at the end.

Given this then, it’s a simple matter of creating a variable to extract the ID value using an XSL function shown below;

substring-after(url, 'ID=')

Published by

Phil Harding

SharePoint Consultant, Developer, Father, Husband and Climber.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.