How to do programming with Repeating Sections? - InfoPath Dev
in

InfoPath Dev

How to do programming with Repeating Sections?

Last post 01-28-2010 06:24 AM by reggieoverton. 7 replies.
Page 1 of 1 (8 items)
Sort Posts: Previous Next
  • 09-03-2008 07:00 AM

    How to do programming with Repeating Sections?

    I am working on a project that requires the user to enter data into a group of fields and then hit a calculate button and then calculations are ran using a vbscript.  The view is changed and the  results are shown in a new infopath view.

    I have this working for the first group of items in the repeating section.

    When I enter data for the second repeating section the script does not work.

    I have figured out that it doesn't work because the XPath is still pointing at the first group in the repeating section.

    In the VBscript, I am using  the following code to access the fields

    object=XDocument.DOM.selectSingleNode("XPATH") 

     How can I make it iterate to the next group in the repeating section?

     

    Brooke Hyde, MCP
    SharePoint Solutions
  • 09-03-2008 08:10 AM In reply to

    Re: How to do programming with Repeating Sections?

    Hi, Brooke:

    Is your button in the repeating group? Or do you have one button that is supposed to calculate all the repeating groups?

    If the button is inside the repeating group, you can use the eventObj variable to select the correct instance of the group.

    Your button's event handler looks something like this (with the CTRL name depending upon the name of your control): Sub CTRL1_5_OnClick(eventObj)

    If you use eventObj.Source.selectSingleNode("xpath") you can get the fields in the group the button is located in. For example, say the xpath to my field is this: /my:myFields/my:topGroup/my:repeatingGroup/my:rgField1 and my button is sitting in my:repeatingGroup. To get my:rgField1, I could use eventObj.Source.selectSingleNode("my:rgField1").

    Now, if you have one button on the whole form, and you want to run calculations for all the groups, instead of using selectSingleNode, you'll use selectNodes and iterate through all the nodes, performing your calculations on each group as you go through. Does that make sense? Let me know if you need more help....

    Hilary Stoupa

  • 09-03-2008 09:15 AM In reply to

    Re: How to do programming with Repeating Sections?

    Hilary,

    Thanks for replying so quickly. 

     My button is inside my sections.

     i have changed my code to read

    set objectvariable = CTRL69_8_OnClick.Source.selectSingleNode("XPath")

    Now I get the following error. Type mismatch: 'CTRL69_8_OnClick'

    I tried commenting that line out to better diagnose and it still gets the same error on that line.  The line that errors is the first line whe I am using the eventobj variable to get data from the form.

    Do I still need to use the set command when getting the data?

    Do you know if I still need to use an object or will a double type variable work?

    Thanks,

     Brooke 

     

     

    Brooke Hyde, MCP
    SharePoint Solutions
  • 09-03-2008 09:56 AM In reply to

    Re: How to do programming with Repeating Sections?

    Whoops, you don't use the CTRL name, you use eventObj. I'm sorry I confused you, I included the event handler sig so you'd see the (eventObj) argument being passed in. Try:

    set objectvariable = eventObj.Source.selectSingleNode("XPath")

    Hilary Stoupa

  • 09-04-2008 09:02 AM In reply to

    Re: How to do programming with Repeating Sections?

    I'm still having some issues. 

    I changed the code to use eventObj instead of the CTRL name.  The code will still execute on the first group but won't execute on subsequent groups.

    The button the executes the script changes the view to a view with the results fields and display the results for the record that data is being entered for.

    When I try to calculate for the second group the script kicks off and then runs calculations for the first group only. The calculations for every group must be calculated.

    I think that I may need to run the calculation for all the groups by iterating through the nodes.

    Could you point me in the right direction to do that?

     

    Brooke Hyde, MCP
    SharePoint Solutions
  • 09-04-2008 09:59 AM In reply to

    Re: How to do programming with Repeating Sections?

    I don't know the VBScript syntax off hand, but you'll want selectNodes instead of selectSingleNode and then your xpath should point to the appropriate node group.

    In C# (IP2003) we use foreach (IXMLDomNode item in variableName) and then put the logic for the loop (in your case, the calculation code) in between some curly braces. I think VBScript uses for each item in variableName, followed by the logic, and finishing with next to move to the next node.

    Here is a link with more info on selectNodes that deals with VBScript.

    Hilary Stoupa

  • 09-04-2008 02:19 PM In reply to

    Re: How to do programming with Repeating Sections?

    Hilary, Thanks so much for all your help!

    I got this working.

    I was having problems because there were groups inside my repeating group.

    I simiplified my XML schema and put all the fields inside the repeating group and it works like a charm.

    Thanks,

    Brooke

     

    Brooke Hyde, MCP
    SharePoint Solutions
  • 01-28-2010 06:24 AM In reply to

    Re: How to do programming with Repeating Sections?

    What if the fields are pointing to access. Meaning the infopath form is connected to access database. How do u point to them using VBscript?

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