SharePoint 2010 Using Parameters in InfoPath forms

If you would like to pass parameters into an InfoPath form, for example to call specific data into the form you can do it really easy. In my case we are using code behind, i am not sure if you can read parameters without using code, but if it is possible please let me know.

As i said you need to add code behind into your form, in order to access the parameters. Afterwords you have to insert the form loading event and use these lines of code:



public void FormEvents_Loading(object sender, LoadingEventArgs e)
{
//Getting the Parameters from Url
string para_ticketId = string.Empty;
if(e.InputParameters.ContainsKey("ticketId"))
para_ticketId = e.InputParameters["ticketId"];

//Setting Parameter into Field of Form
XPathNavigator navForm = this.CreateNavigator();
XmlNamespaceManager NS = this.NamespaceManager;

navForm.SelectSingleNode("/my:meineFelder/my:TicketID", NS).SetValue(para_ticketId);

}


By using the e.InputParameters[“yourparameter”] you can access the values of the parameter. By using the contains key you can check if the parameter is attached to the url. This is important that you don’t get an error message cause the parameter is missing. It’s better to check it by yourself and give a nice error message to the user.

Now your InfoPath form can read the parameter and write it into any field you like. If you open the InfoPath form by using this adress:

http://yourserver/sites/yourSiteCollection/_layouts/FormServer.aspx?xsnLocation=~sitecollection/FormServerTemplates/yourInfoPathForm.xsn&openin=browser&ticketId=ilikesharepoint

The InfoPath form writes this value “ilikesharepoint” into the desired field:

Hope this helps you a little bit. If you would like to know more about, i recommend you to read this great post.

..:: I LIKE SHAREPOINT ::..

The article or information provided here represents completely my own personal view & thought. It is recommended to test the content or scripts of the site in the lab, before making use in the production environment & use it completely at your own risk. The articles, scripts, suggestions or tricks published on the site are provided AS-IS with no warranties or guarantees and confers no rights.

Karsten Pohnke About Karsten Pohnke
He is Consultant for SharePoint Solutions for collaboration, communication and business processes. He provides his customers applications based on standard features as well as development or combining the power of several microsoft tools like Dynamics CRM. In his free time he tries to collect tipps and worthy experience in this blog.

2 comments on “SharePoint 2010 Using Parameters in InfoPath forms

  1. Vladimir

    Hello!
    You can learn how to make it work in a browser form infopath?
    Thanks.

Submit comment

Allowed HTML tags: <a href="http://google.com">google</a> <strong>bold</strong> <em>emphasized</em> <code>code</code> <blockquote>
quote
</blockquote>

Please fill in the captcha: * Time limit is exhausted. Please reload CAPTCHA.