Check if an Input Parameter Exists - InfoPath Dev
in

InfoPath Dev

Check if an Input Parameter Exists

Last post 07-05-2011 08:03 PM by Jimmy. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 07-05-2011 01:21 PM

    Check if an Input Parameter Exists

    Hi All, I have a scenario where a user can open a form (stored in an SP2007 Form Library) via a URL that passes input parameters or they can open the form via the New button in a SharePoint Forms Library (no custom input parameters). When the user clicks the URL with parameters, everything works great, the URL parameters are passed in and my code in the Form_Submit event reads them and fills in the fields. But when they use the New button, try as I might, I cannot get the code to detect that the parameters are not present. I always get a 'System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary' error. I have tried e.InputParameters.ContainsKey, e.InputParameters.TryGetValue and I have tried just checking for null. In each case, I get the error when that line of code is executed (or even the line before that just declares a string variable, which is really strange?). I am new to InfoPath coding and coding in general so maybe I am missing something very obvious. Here is the code I am currently using:

    string jobnumber;
    if (e.InputParameters.TryGetValue("jobnumber", out jobnumber))
    {
    XPathNavigator xnJobNumber = main.SelectSingleNode("/my:myFields/my:JobNumber", this.NamespaceManager);
    xnJobNumber.SetValue(jobnumber);
    }

    Can anyone help? Thanks!
  • 07-05-2011 08:03 PM In reply to

    Re: Check if an Input Parameter Exists

    Two thinks you can do: 1. Iterate through all the items in the InputParameters collection, looking for the one you want.  This will also let you do a case-insensitive match on the key.  or 2. Place your lookup in a try-catch block.

    Either approach should work if the key is right, though I recommend the former.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
Page 1 of 1 (2 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.