Cascading Dropdown Boxes, Repeating - InfoPath Dev
in

InfoPath Dev

Cascading Dropdown Boxes, Repeating

Last post 04-30-2007 06:44 PM by kaleo. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 04-26-2007 04:14 PM

    • R.Allen
    • Not Ranked
      Male
    • Joined on 04-26-2007
    • Portland, Maine
    • Posts 2

    Cascading Dropdown Boxes, Repeating

    Hello,

    I have read through a ton of forums so far and have not found this yet. If it's been discussed and I missed it then I apologize...

     Situation:

          There are 4 tables involved in this form.

                Table1 (Main Connection)

                Table2 (Secondary Connection, Stores Look-up items for DBox2 Directly related to Table4)

                Table3 (Secondary Connection, Stores Look-up items for DBox3, Directly related to Table4)

                Table4 (Secondary Connection, Stores values selected from DBox2&3, Directly related to Table1)

          I have DBox2 that looks at Table2 and stores to Table4, Then DBox3 that looks at Table3 and also stores to Talbe4. DBox3 is filtered by DBox2. This works perfectly.

    DBox Example

     

     

    Problem I'm having:

          I want them to be able to select an option in DBox2, then DBox3, then be able to insert a row and do the same. When I insert a row into the repeating table(or section, tried both) the list changed but shows the contents in DBox3 related to both DBox2's.

    Question:

           Is there a way to make it only look at the "row" that I am working on and not just the field name as even when you insert a row, it's still the same field and all the one's selected above are applied to that filter?

     Thank You!

     ~Richard Allen

  • 04-26-2007 05:37 PM In reply to

    • kaleo
    • Not Ranked
      Male
    • Joined on 04-26-2007
    • Honolulu, Hawaii
    • Posts 17

    Re: Cascading Dropdown Boxes, Repeating

    Hello Richard,

    Try setting the XPATH to a relative position...

    For Example instead of:

    "/my:myFields/my:Field1"

    Make it

    "../my:Field1"

    InfoPath 2007 Managed Code (VB):

    Dim XPN As XPathNavigator = Me.MainDataSource.CreateNavigator()

    Dim Field1Node As XPathNavigator = XPN.SelectSingleNode("../my:Field1", Me.NamespaceManager)

    'Use the Field1Node.Value to populate the rest of the table.

    Kaleo

  • 04-27-2007 12:13 PM In reply to

    • R.Allen
    • Not Ranked
      Male
    • Joined on 04-26-2007
    • Portland, Maine
    • Posts 2

    Re: Cascading Dropdown Boxes, Repeating

    Hello Kaleo,

     I am not extremely familiar with coding but I'll give it a shot, would you be able to provide the JScript version of this? I'm using InfoPath 2003 if that helps.

     Thanks for you help!

    ~Richard

  • 04-30-2007 06:44 PM In reply to

    • kaleo
    • Not Ranked
      Male
    • Joined on 04-26-2007
    • Honolulu, Hawaii
    • Posts 17

    Re: Cascading Dropdown Boxes, Repeating

    Hello Richard,

    You're in luck! becuase I wrote a "Contact Sheet" in InfoPath 2003 when I First Encountered this issue.

    Unfourtunately, I haven't a clue how to write Jscript but I wrote it in Visual Basic Script which would be applicable with InfoPath 2003.

    When the contact is selected, with the "Full Name" Pull Down it then Populates that users Email address and Phone Number.

    Regardless of which row I changed it should always update the corresponding row (of course)

    • First, Set your "Form Options" to use 'VB Script"
    • Then create the Repeating Table Below:
      • Respectively: Field1, Field2, Field3

    Project Contact Sheet

    • Then added a Data Connection that queries the contact information I need.

    The Data Connection could be SQL or Sharepoint or whatever, but remember what you named the datasource. (mine was Called "Contacts" and it Queried a Sharepoint List.)

    • Then add a "On After Change Event", by selecting the pull down and right-click - select it from the "Programming" menu

    It should add the Following Sub to your project

    BOLD: new Code to Write

    Italic: my Comments

    Sub msoxd_my_field1_OnAfterChange(eventObj)

    Dim MyDataConnection

    Set MyDataConnection = XDocument.DataObjects("Contacts").DOM

    'This sets the reference to your Data Connection we made where "Contacts" is the name of your Data Connection

    MyDataConnection.setProperty "SelectionNamespaces", "xmlns:dfs=""http://schemas.microsoft.com/office/infopath/2003/dataFormSolution"" " & _

    "xmlns:dsf=""http://schemas.microsoft.com/office/infopath/2003/dataFormSolution"" "

    'This enables us to call the additional nodes within our Data Connection

    Dim CurrentContact

    CurrentContact = eventObj.Site.selectSingleNode("../my:field1").text

    'This is where we set the relative Xpath to the Current Row (if the Xpath was "my:fields/my:group1/my:field1" then it would always return the first row in the table)

    Dim DataNode

    DataNode = MyDataConnection.selectSingleNode("/dfs:myFields/dfs:dataFields/dsf:Contacts[@Full_Name='" & CurrentContact & "']")

    'This Queries the Record in the DataConnection where Full_Name = Field1 (CurrentContact)

    If (CurrentContact <> "") Then

    'This is just in case the Field is Blank on "update" it won't return an error

    If TypeName(DataNode.attributes.getNamedItem("E-mail_Address")) <> "Nothing" Then

    'This is just in case the user doesn't have an email address the form won't return an error

    eventObj.Site.selectSingleNode("../my:field2").text = DataNode.attributes.getNamedItem("E-mail_Address").text

    'Thes sets Field2 (email address) to the address in the DataNode Query we created

    End If

    If TypeName(DataNode.attributes.getNamedItem("Business_Phone")) <> "Nothing" Then

    'This is just in case the user doesn't have a phone number the form won't return an error

    eventObj.Site.selectSingleNode("../my:field3").text = DataNode.attributes.getNamedItem("Business_Phone").text

    'Thes sets Field3 (Phone Number) to the Phone Number in the DataNode Query we created

    End If

    End If

    If eventObj.IsUndoRedo Then

    ' An undo or redo operation has occurred and the DOM is read-only.

    Exit Sub

    End If

     'A field change has occurred and the DOM is writable. Write code here to respond to the changes.

    End Sub

     Hope this helps!

    Kaleo

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