What is this about? Well, I needed a custom SharePoint list, with a customized InfoPath form for it, and this form had to read one parameter from the URL. Nothing complicated at all, there are many posts on how to customize forms for SharePoint lists and how to pass an URL parameter for this form. But in my case I needed it all deployable with a package and this puts another level of complexity. Therefore I decided to wrap the procedure in the post below - to make sure that I don’t forget it after a while.
If you don’t know how to customize InfoPath form for SharePoint list you should check this article first: click. Another interesting post to read is how to pass query string data to InfoPath form: click. These are the basics we need before moving on with wrapping it all in a package.
To be honest, I did not discover the wheel on how to deploy InfoPath 2010 list form with VisualStudio package. I followed this post: click and it works like charm :) I will not duplicate the post, but would like to summarize it in few steps:
1. Create the basic solution in VisualStudio - fields, content type (if needed), list and deploy them to your dev site
2. Customize the InfoPath form and export it with SharePoint designer. Form is located in All Files –> Lists –> Your list –> Item and by default it’s title is “template.xsn”
3. Create 3 modules in VisualStudio: One to deploy the form, one for list pages with InfoPath webpart and one to adjust InfoPath form properties (to define that form opens with InfoPath Form Services)
4. Customize content type schema to change the default pages to the newly created
Now, once form is customized and this procedure is clear, will move on with query filter parameter and how to deploy the webpart and create the connection to the InfoPath form webpart. I did it with code that attached on feature activated event. Code contains 2 pieces: first will add QueryStringFilterWebPart to New form page and then will create a connection between the existing BrowserFormWebPart (this is the InfoPath form webpart) and the new query filter webpart. Actually the first step is to take the page and find its webpart manager:
After that have to create and attach the query string webpart:
The 2 most important properties here are “QueryStringParameterName” that keeps the URL parameter name to read, and “FilterName” that keeps the name of the newly created filter. All other parameters in the collapsed region I took from SharePoint 2010 designer – opened a page with a QueryStringFilterWebPart and checked all properties from there.
Once the query string webpart is attached to the page it is time to connect the 2 webparts:
To create a connection between webparts we need to define the Provider and Consumer webparts. In our case provider is the QueryStringFilterWebPart, the consumer is InfoPath BrowserFormWebPart. Important here is to define a pattern on how both webparts communicate. This is done with “TransformableFilterValuesToParametersTransformer” object. The provider field name in this example is “QueryString” (the one defined in “FilterName” parameter in query string webpart). For consumer I use “TestIP_TextField” – this is one if the SharePoint fields created in the custom list. Once connection is created it is attached to webpart manager on the page.
Final step is to deploy and test the solution. In my case the result looks like this:
The URL for this call looks like this: http://[server_name]/Lists/[list_name]/Item/newifs.aspx?InParam=param
The code for this post can be downloaded from here: click
Hi Petra i followed the same steps as above. The only change is i used Sharepoint List Template in infopath designer and then selected the list and its content type to create the form and then i published it and downloaded it as template and then continued with the 4 steps you have mentioned .
ReplyDeleteBut when i deploy the solution everything is deployed properly. But when i try to create a new list item i get the sharepoint error message: Form control does not have ControlMode set . I don't know what is the problem. I refered to this post
http://social.msdn.microsoft.com/forums/en-ZA/sharepointdevelopmentprevious/thread/4d96bf0d-b928-494d-87ab-1216a85fdbda
but there is no solution to it.
Do you have any ideas what is wrong. Also in my content types there are atleast 5 lookup fields but i guess that won't be a problem. Any help would be deeply appreciated.