Tuesday, April 2, 2013

Display list item in edit mode in InfoPath Form Web Part


In this post we are going to see how we can open a list item in edit mode in InfoPath Form Web Part. This initially seems to be an easy job. But it is not.

I really had to invest a lot of time figuring out this solution. What we want to achieve is actually a list form customized using InfoPath by using customize this form in InfoPath ribbon option and then by using the InfoPath form web part we display the form of the list.
I have a list called orders.



and I have used customized the form in InfoPath option from ribbon so that new item, edit item and view item opens up in InfoPath form and not the list form.





If you select the list item and click on edit the item, you can see item is opened in the InfoPath.



Now here comes a tough part. Assume that you want to have another web parts on the page and on the same web part page you would like to have this order list item new entry form to be displayed.

Well, this is not as tough as you think. you can simple add the InfoPath form web part and then set the list name to order and you are good to go.



Once you click on ok, you can see the form has been added on the web part.



Now comes the challenging part, how would you open any list item in the InfoPath Form Web Part. Now again this seems an easy job but it is not as I stated earlier.

I had to go through lot of blog posts and articles. Many of them mentioned that you need to have source list and then bind the connection between InfoPath Form web part and source list so that when you select the source list item, that item gets populated in the InfoPath Form Web Part.

However this is not the solution that we want. We cannot add a source list in our case, orders to the same page and connect these two web part.

There can be a scenario where you are just passing ID of the list item from another page and based on the query string you want to show the edit form in the InfoPath form web part.

So here is a solution that I came out with. But yes if you do not have code option available to you, then you have to go with the connect web part approach. But for that you will have a list also displayed on the same web part page.

All we need to do is create one simple web part (not the visual web part) . add a reference to the c:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI\Microsoft.Office.Server.dll DLL.

protected override void CreateChildControls()
        {
            BrowserFormWebPart web = new BrowserFormWebPart();

            web.FormLocation = @"{siteURL}/Lists/Orders/Item/editifs.aspx?List={list GUID}&LItemID={ITEMID}&Source={siteURL}%2FLists%2FOrders%2FAllItems%2Easpx&ContentTypeId=0x01005AFFDCC34451FF46B97FDD902EA436AF";
            this.Controls.Add(web);

        }

Just replace the List GUID, site URL and ID with the actual list GUID, site URL and list item ID. you can get these through query string or as per your requirement.

Deploy the web part and you are good to go. Now you have a InfoPath Form web part which shows list item in edit mode. 

No comments:




Share your SharePoint Experiences with us...
As good as the SharePointKings is, we want to make it even better. One of our most valuable sources of input for our Blog Posts comes from ever enthusiastic Visitors/Readers. We welcome every Visitor/Reader to contribute their experiences with SharePoint. It may be in the form of a code stub, snippet, any tips and trick or any crazy thing you have tried with SharePoint.
Send your Articles to sharepointkings@gmail.com with your Profile Summary. We will Post them. The idea is to act as a bridge between you Readers!!!

If anyone would like to have their advertisement posted on this blog, please send us the requirement details to sharepointkings@gmail.com