Sunday, September 28, 2014

Opening InfoPath Form in Modal Dialog

Question 


How to open InfoPath New and Edit forms in the Modal dialog?


Answer


Let us start with new fresh InfoPath Library. Create an InfoPath Library and call it "AccordionForms". The path of library would be like,


Let us examine new and edit form URLs.


New InfoPath Form:


If you click on the new item link, it would redirect to URL,




I have added added "..............." intentionally in the URL because I do not want you to confuse in the long URL. Let us dissect it. 
  1. FormServer.aspx is the page present in 14 hive. This is the page that is called when we add/update of InfoPath form is done. In URL, this page name is constant.
  2. XsnLocation: This parameter is used for opening new InfoPath forms.
  3. SaveLocation: This parameter is used to tell InfoPath Form that which InfoPath library, form is needed to be submitted.
  4. Source: This Parameter is Used to tell InfoPath Form that after submission, which URL to navigate to. This parameter works if we set "Close Form after Submission" option in InfoPath Designer. See the following example, by default source URL would be http%3A%2F%2Fmyserver%2Fsubsite%2FAccordionForm%2FForms%2FAllItems%2Easpx but I have changed it to default.aspx (http%3A%2F%2Fmyserver%2Fsubsite%2Fdefault%2Easpx) because I want user to navigate to different page than the default listing page.

Now the final URL looks like following,



Edit InfoPath Form:



If you navigate to AccordionForms library and click on any submitted InfoPath form, it will navigate to URL that would look like,


The URL looks similar to the add URL except,
  1. XMLLocation: in Add URL, we used XSNLocation because it was new form and we needed a template. But now, the form is already submitted and it is in XML format now so we will use XMLLocation parameter.
  2. We will not provide saveLocation parameter.

The final URL looks like following,



Specifying InfoPath View

If you want to open the above form in specific view , we need to add following line at the end of URL,

"&DefaultView=" + viewName


The above "viewName" is the name of InfoPath view. the final url will become,

http://myserver/subsite/_layouts/FormServer.aspx?XmlLocation=........&ClientInstalled=false&Source=.............&DefaultItemOpen=1&DefaultView=ViewOnly

The above URL will open InfoPath form with "ViewOnly" view (of InfoPath).



Open Form in Modal Dialog


We will use SharePoint UI JavaScript library to open the edit or edit form in popup. Following is example of opening the above edit form in Modal Dialog through Link,

<div> <a href="javascript:{ SP.UI.ModalDialog.OpenPopUpPage('



Form Server Page Query String Parameters


Please look at the table below that was published on MSDN http://msdn.microsoft.com/en-us/library/office/ms772417(v=office.14).aspx


Parameter Name
Description
Allowed Values
XmlLocation
Used to open an existing form. The XmlLocation and XsnLocation properties are mutually exclusive; specifying values for both parameters will result in an error.
A valid URL to a form file (.xml) in the same site collection.
XsnLocation
Used to open a new form that is based on a form template. If an XsnLocation is specified in a URL using FormServer.aspx, a SaveLocation should also be specified if the Save and Save As buttons must be displayed. The Source parameter should also be specified or the message "The form has been closed" will appear when the user closes the form. The XmlLocation and XsnLocation properties are mutually exclusive; specifying values for both parameters will result in an error.
A valid URL to a form template file (.xsn) published on the same site collection.
OpenIn
    • If a Source query parameter is specified, the default value is Browser.
    • If XmlLocation is specified, the default value is the setting used in the library.
    • If only XsnLocation is specified, the default value is PreferClient.
    • If Mobile is specified, the form will be redirected to the MobileFormServer.aspx page for rendering. The form template must be enabled for mobile support or an error message will be returned.
    • Browser
    • Client
    • PreferClient
    • Mobile
Source
The location to which the user will be redirected when the form is closed. The URL must be in the same site collection or an error will be returned.
A valid URL in the same site collection as the form.
Options
DisableSave is the only allowed value. It hides the Save and Save As buttons and disables saving the form when it is rendered in the browser.
DisableSave
SaveLocation
Save As dialog box is displayed prompting the user for a file name, and then it is saved in the specified folder. An error is returned if the specified folder does not exist.
Any valid folder location on the site collection.
NoRedirect
Does not redirect to FormServer.aspx for client detection or rendering in the browser. Default value is false. If true and an XmlLocation or XsnLocation is specified, a File Download dialog box is displayed when you are using Internet Explorer.
    • true
    • false (default)
DefaultItemOpen
The OpenIn parameter should be used instead, and overrides the DefaultItemOpen parameter value. A value of 0 indicates that the request is from a document library and the InfoPath Filler was not detected. A value of 1 indicates that the request is from a document or form library that has the Display as a Web page setting.
    • 0
    • 1

No comments:

Post a Comment