Tuesday, 3 January 2012

SharePoint No-Coding: Open any InfoPath Form

On the latest project I was working, had to develop a SharePoint solution by using only InfoPath and SharePoint designer as development tools. Well, at first felt a bit upset, still I am a developer, and someone just took away my most favorite toy – VisualStudio. After a while, accepted the situation as a new challenge and this made things look better. In this, and the posts that will follow will try to cover some interesting moments from the development process on a no-coding solution for SharePoint 2010.

One of the first things that had to do is a web page that contains specific item metadata on the top and an InfoPath form to gather additional information under it. There were several different form types to display the same way, so I decided to use one page for all of them. There is no problem to add InfoPath Form Web Part and to associate it with some source from the web. Adding Data Form Web Part for the metadata on top is even easier. But my page had to load different InfoPath form templates to create new items, and show existing forms as well. Soon realized that can do something similar to what FormServer.aspx page does – to open a form by passing its location as URL parameters. This is why I created a web parts page and added one InfoPath Form Web Part to it. The InfoPath Web Part kept as it is – without associating it with specific form source. Then depending on URL input parameters this web part was loading either exiting form item, or a form template to create new item. To create new form XsnLocation parameter should be used, and the URL looks something like this:
http://server/sites/mysite/SitePages/OpenForm.aspx? XsnLocation=/sites/mysite/FormServerTemplates/MyTemplate.xsn

Where MyTemplate.xsn is the form template to load and it is located in FormServerTemplates library on the website.
To open existing form in edit mode have to pass XmlLocation as parameter. The URL looks like this:
http://server/sites/mysite/SitePages/OpenForm.aspx?XmlLocation=/sites/mysite/MyFormsLibrary/MyForm.xml

Here MyForm.xml is the existing form and it is located in MyFormsLibrary library.
Note that XsnLocation and XmlLocation properties are matually exclusive – if you include both of them will result an error.
As simple as that I was having a single page to perform multiple operations.
For more information on query parameters for InfoPath browser-enabled forms click here: MSDN 'How To'

6 comments:

  1. Dude. Woman. Miss. Lady. Very awesome. This is quite helpful. You have my sincerest and heartfelt gratitude.

    ReplyDelete
  2. Excellent, i spent hours for this before seeing your blog. Thanks for sharing.

    ReplyDelete
  3. One issue, you cannot use the XmlLocation and define the default view. I can create a page using the InfoPath Viewer Web Part, call the correct form from the relative form library; however that web part actually builds the XSNLocation path for you. By doing this, you cannot call the XmlLocation to load the data into the default view. I can't see any way around this without code.

    ReplyDelete
  4. This is a very nice and useful article.

    ReplyDelete
  5. Hello, I know this post is older, but I am having the hardest time figure this out. I have an infopath web part on a page. I want to be able to determine if the current user has submitted a form already. If so, open that instance of the form for edit. If not open the form as a new item. The user coming in will only have the url to the page. Any ideas?

    ReplyDelete
  6. This is a very nice and useful article

    ReplyDelete