How to use input parameters ? - InfoPath Dev
in

InfoPath Dev

How to use input parameters ?

Last post 10-01-2008 07:50 AM by Hilary Stoupa. 9 replies.
Page 1 of 1 (10 items)
Sort Posts: Previous Next
  • 09-29-2008 07:54 AM

    How to use input parameters ?

    Just back from the Master Class and I am trying to implement some Input Parameters. I am using InfoPath 2007, MOSS and VB

    I have created a form, Candidate Evaluations and published it to a sharepoint site.  It has the following code

    Public Sub FormEvents_Loading(ByVal sender As Object, ByVal e As LoadingEventArgs)
    ' Write your code here.
    'Try
    Dim VacIDin As String = "9999"
    Dim VacParam As Boolean = e.InputParameters.TryGetValue("VacID", VacIDin)
    Dim Candidatein As String = "aaaaaa"
    Dim CandidateParam As Boolean = e.InputParameters.TryGetValue("CandName", Candidatein)
    Dim VacancyIDfield As XPathNavigator = Me.CreateNavigator.SelectSingleNode("/my:myFields/my:FormFieldsGroup/my:VacancyID", NamespaceManager)
    Dim CandidateName As XPathNavigator = Me.CreateNavigator.SelectSingleNode("/my:myFields/my:EvaluationFormGroup/my:CandidateName", NamespaceManager)
    If VacParam = True Then
    VacancyIDfield.SetValue(VacIDin)
    End If
    If CandidateParam = True Then
    CandidateName.SetValue(Candidatein)
    End If
    'Catch ex As Exception
    'End Try
    End Sub

    From another form I use the following URL  http://in/hr/ATS/Candidate Evaluations/Forms/template.xsn?VacID=2&CandName=john doe

    The form opens but my values have not been passed in.  What else do I need to do ?  How can I debug using these input parameters ?  I don't know where it is failing. 

    Thank you

    Catharine

     

     

  • 09-29-2008 09:53 AM In reply to

    Re: How to use input parameters ?

    Hi, Catharine:

    If you uncomment your try/catch, and add a message box to show the error caught (MessageBox.Show(ex.Message)), do you get an error?

    If you try opening the form from a file location (like a local folder) using the command line with the /Input Parameters switch, do you have different results? (This link has more info on the command line).

    I'm more familiar with C# than VB -- but I'm a little confused by your code. When I've seen the TryGetValue method used in other samples, it uses the C# keyword out to set a variable value, so:

    string vacID = string.Empty;

    e.InputParameters.TryGetValue("VacID", out vacID);

    would be used to set the value of the string variable vacID. I'm not sure if VB has similar functionality. To get the value of an input parameter, you can use:

    Dim VacIDin As String = e.InputParameters("VacID")

    Hilary Stoupa

  • 09-29-2008 10:17 AM In reply to

    Re: How to use input parameters ?

    I have changed to

    Public Sub FormEvents_Loading(ByVal sender As Object, ByVal e As LoadingEventArgs)

    ' Write your code here.
    Try
    Dim VacIDin As String = e.InputParameters("VacID")
    MessageBox.Show(VacIDin)
    'Dim VacParam As Boolean = e.InputParameters.TryGetValue("VacID", VacIDin)
    Dim Candidatein As String = e.InputParameters("CandName")
    MessageBox.Show(Candidatein)
    'Dim CandidateParam As Boolean = e.InputParameters.TryGetValue("CandName", Candidatein)
    Dim VacancyIDfield As XPathNavigator = Me.CreateNavigator.SelectSingleNode("/my:myFields/my:FormFieldsGroup/my:VacancyID", NamespaceManager)
    Dim CandidateName As XPathNavigator = Me.CreateNavigator.SelectSingleNode("/my:myFields/my:EvaluationFormGroup/my:CandidateName", NamespaceManager)
    'If VacParam = True Then
    VacancyIDfield.SetValue(VacIDin)
    'End If
    'If CandidateParam = True Then
    CandidateName.SetValue(Candidatein)
    'End If
    Catch ex As Exception
    MessageBox.Show(ex.Message)
    End Try
    End Sub

    and I get the error - The given key was not present in the dictionary. 

  • 09-29-2008 10:39 AM In reply to

    Re: How to use input parameters ?

    Do you get the error when you use the command line input parameters switch?

    Hilary Stoupa

  • 09-29-2008 10:47 AM In reply to

    Re: How to use input parameters ?

    No I am trying to call it with parameters from sharepoint using  http://invistanet-eur/hr/ATS/Candidate Evaluations/Forms/template.xsn?VacID=1&CandName=john doe 

  • 09-29-2008 11:35 AM In reply to

    Re: How to use input parameters ?

    Right, I understand that. I was just thinking for troubleshooting, that I'd try to save the form locally and use the input parameters from the command line to see if it worked.

    Hilary Stoupa

  • 09-30-2008 02:54 AM In reply to

    Re: How to use input parameters ?

    Sorry I misunderstood - yes I get the error message when using the command line.  I don't find using the command line as easy as using parameters and the URL.

  • 09-30-2008 07:19 AM In reply to

    Re: How to use input parameters ?

    I guess I find it a bit easier for troubleshooting, because I don't have to publish the form out after making changes. Well, the error is basically saying that you are asking for an input parameter in your code that you aren't providing when you open the form. From the command line, you need to be sure to have a space after infopath.exe, the form path, the /Input Parameters switch and the parameters, so each item is space delimited.

    infopath.exe "C:\template.xsn" /InputParameters "VacID=23&CandName=John Doe"

    Since you are getting your error prior to any message showing the parameter value, we know that the code is failing on the first line. Perhaps try simplifying even further and only have one input parameter to start with?

    Hilary Stoupa

  • 09-30-2008 10:25 AM In reply to

    Re: How to use input parameters ?

    I have changed the code to be....

    Public Sub FormEvents_Loading(ByVal sender As Object, ByVal e As LoadingEventArgs)

    ' Write your code here.

    Try

    Dim VacIDin As String = e.InputParameters("VacID")

    MessageBox.Show(VacIDin)

    'Dim VacParam As Boolean = e.InputParameters.TryGetValue("VacID", VacIDin)

    'Dim Candidatein As String = e.InputParameters("CandName")

    'MessageBox.Show(Candidatein)

    ''Dim CandidateParam As Boolean = e.InputParameters.TryGetValue("CandName", Candidatein)

    Dim VacancyIDfield As XPathNavigator = Me.CreateNavigator.SelectSingleNode("/my:myFields/my:FormFieldsGroup/my:VacancyID", NamespaceManager)

    MessageBox.Show(VacancyIDfield.InnerXml)

    'Dim CandidateName As XPathNavigator = Me.CreateNavigator.SelectSingleNode("/my:myFields/my:EvaluationFormGroup/my:CandidateName", NamespaceManager)

    ''If VacParam = True Then

    VacancyIDfield.SetValue(VacIDin)

    MessageBox.Show(VacancyIDfield.Value)

    ''End If

    ''If CandidateParam = True Then

    'CandidateName.SetValue(Candidatein)

    ''End If

    Catch ex As Exception

    MessageBox.Show(ex.Message)

    End Try

    End Sub

    When I call this from my SharePoint using http://invistanet-eur/hr/ATS/Candidate%20Evaluations/Forms/template.xsn?VacID=2

    I get the error message the Given key is not in the directory

    When I call this from the command line using infopath.exe c:\candidateevaluation.xsn /inputparameters Vacid=2

    I get the message 2 followed by the Given key is not in the directory - no other message boxes appear

  • 10-01-2008 07:50 AM In reply to

    Re: How to use input parameters ?

    It turns out that when we use a URL to open the form and pass in input parameters, the parameter key passed in is changed to lower case. So, for example, if you use "VacID" as the parameter key in your Loading event, and "VacID" as the query parameter in your hyperlink, the Loading event actually receives "vacid" and will return a "given key not in dictionary" error.

    When we changed the Loading event code to use "vacid" as the key, the query parameter in the hyperlink could be "VacID" or "vacid" (or any other combination of upper and lower case) and the key was found.

    This will also probably affect the candiate name. "John Doe" will be changed to "john%20doe" and you'll need to handle for that in your code, using string functions like Replace to change %20 back to spaces, and VbStrConv.ProperCase to set the first letters of each word back to a capital letter

    Hilary Stoupa

Page 1 of 1 (10 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.