URL Input Parameters 'Gotcha' - Hilary Stoupa

InfoPath Dev

Hilary Stoupa

URL Input Parameters 'Gotcha'

Ah, input parameters. It is so nice to be able to open a form with some values already filled in, isn't it? Except, of course, when they don't work. And to say they are a bear to debug would be an enormous understatement.

I was recently helping a forum user with a form using input parameters passed in from a URL. Every thing looked exactly right. But try as we might, we kept getting an error:
Given Key Not Present error

And the field we wanted filled from the parameter remained blank:
Sad and blank field

For purposes of demonstration, I'll modify this code posted on MSDN for the LoadingEventArgs.InputParameters property.

My form code looks like this:

        public void FormEvents_Loading(object sender, LoadingEventArgs e)
                string vDept = e.InputParameters["Dept"];
                XPathNavigator myNav = CreateNavigator();
                myNav.SelectSingleNode("/my:TestForm/my:Department", NamespaceManager).SetValue(vDept);
            catch (Exception ex)

Now, you'll notice that unlike the MSDN sample, I've added a little bit of error handling. Without it, the input parameters fail silently. While that may be the preferred end result, while trying to figure out why your parameter isn't populating a form field -- well, without a try/catch, you'll end up weeping and smacking your forehead against your desk. We don't want that.

Basically, all this code does is get the value of the input parameter, and set a form field to that value. To use the parameter, you'd add it to the URL for the template, like this:

Sadly, follow this exactly and you will get the "Given Key not Present" error. Want to know why? Because on its way to your form, that parameter key got dropped to lower case. So did the value. So we think we are sending in 'Dept' and 'Accounting' but in fact we are sending 'dept' and 'accounting'. Modify the code to:

string vDept = e.InputParameters["dept"];

Guess what? No more error. Republish the form, and you can use the same input parameters from the URL above to open the form with the Department field filled:
Populated field
Do you notice the case of the word 'accounting'? The value passed was 'Accounting' -- and that is what lead me to guess that the parameter key was being changed to lower case as well.

One last thing to keep in mind with URL input parameters -- be aware you are going to have to do some clean up if you are passing in strings like this. First off, you are going to lose any capitalization. Secondly, if you are passing in a string with spaces, be prepared to clean out all the '%20's.



h.elshabini said:

thank you, very informative this has been driving me crazy :)

December 14, 2008 12:03 AM

ZhenYuan said:

Hi Hilary,

The code didn't work for me... I tried:

Dim vIssue As String


              vIssue = e.InputParameters("oi")

               Me.CreateNavigator().SelectSingleNode("my:myFields/my:Form_Container/my:Issue_View", Me.NamespaceManager).SetValue(vIssue)

           Catch invalid As Exception

               MessageBox.Show("Invalid input", "Error", MessageBoxButtons.OK)

           End Try


Even as I appended ?oi=1 where 1 is what I want as input string, my exception is always thrown. I'm using DBXL by the way. This works for DBXL on IP2007 I hope? And just to be safe, I used all small caps.

December 22, 2010 3:25 AM

About Hilary Stoupa

I wandered into development after working as a business process analyst for a global manufacturing company. I create InfoPath solutions for our clients as well as work as a developer on company tools that extend InfoPath. I've also been instrumental in creating the InfoPath Master Class training provided by Qdabra.

Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.