Code for multiple rows in a repeating table (VB) - InfoPath Dev
in

InfoPath Dev

Code for multiple rows in a repeating table (VB)

Last post 03-26-2012 04:48 PM by Anson Hidajat. 12 replies.
Page 1 of 1 (13 items)
Sort Posts: Previous Next
  • 03-14-2012 08:57 AM

    Code for multiple rows in a repeating table (VB)

    Hello, I have a repeating table that users will use to enter their leave hours. I have fields for startDate, endDate, reason, and hours. I've gotten to the point where it checks the difference between the dates, multiplies the number of days take off by 7.5 (hours in a full work day) and sets the hours field to that number. The only problem is that it only works on the first row. I'm sure the solution is simple but so far I haven't found anything very helpful. Thanks!
  • 03-16-2012 04:23 PM In reply to

    Re: Code for multiple rows in a repeating table (VB)

    You are doing this in code? What's your code look like?

    Hilary Stoupa

  • 03-19-2012 06:19 AM In reply to

    Re: Code for multiple rows in a repeating table (VB)

    Hello, I'm writing this in VB. It runs when the second date changes, pulls InnerXML from each of the dates, runs it through a function I found on here that calculates the number of work days in a given range then multiplies it by 7.5 (because we're working with hours). If you'd like to see the actual code I can attach that.
  • 03-19-2012 08:27 AM In reply to

    Re: Code for multiple rows in a repeating table (VB)

    In general, the reason this happens is because the code uses an absolute XPath instead of a relative XPath. Without seeing your actual code, of course, I have no way of knowing why your code is not working as anticipated.

    Hilary Stoupa

  • 03-19-2012 08:40 AM In reply to

    Re: Code for multiple rows in a repeating table (VB)

    That makes sense. What would a relative Xpath look like? Here's most of the code. Thanks for helping me out :) also: is there a way to insert line breaks or format for code in this forum? that looks terrible. Dim startDate, endDate As XPathNavigator Dim dayDifference As Integer Dim hours As String startDate = (MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:Info/my:UserInput/my:HoursEntry/my:StartDate", NamespaceManager)) endDate = (MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:Info/my:UserInput/my:HoursEntry/my:EndDate", NamespaceManager)) Dim startDateinnerxml, endDateinnerxml As Date startDateinnerxml = startDate.InnerXml endDateinnerxml = endDate.InnerXml If Not startDate Is DBNull.Value Then dayDifference = WorkDays(startDateinnerxml, endDateinnerxml) + 1 MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:Info/my:UserInput/my:HoursEntry/my:dayDifference", NamespaceManager).SetValue(dayDifference) hours = dayDifference * 7.5 MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:Info/my:UserInput/my:HoursEntry/my:Hours", NamespaceManager).SetValue(hours) End If
  • 03-19-2012 09:02 AM In reply to

    Re: Code for multiple rows in a repeating table (VB)

    This code is on the change of a field w/in the repeating table?

    This is an absolute XPath:

    /my:myFields/my:Info/my:UserInput/my:HoursEntry/my:StartDate

    It starts at the root node.

    The method signature for the field that you added the changed event to will look something like this:

    Public Sub field2_Changed(ByVal sender As Object, ByVal e As XmlEventArgs)

    You can use e.Site to get the field you are currently on. More on MSDN here and here. You can use a relative XPath then to get to your other fields, like perhaps:

    e.Site.SelectSingleNode("../my:EndDate", NamespaceManager)

     

     

    Hilary Stoupa

  • 03-19-2012 09:49 AM In reply to

    Re: Code for multiple rows in a repeating table (VB)

    So I should leave the handler as is when I create the changed event (AddHandler EventManager.XmlEvents("/my:myFields/my:Info/my:UserInput/my:HoursEntry/my:EndDate").Changed, AddressOf EndDate_Changed) or make the Xpath dynamic?
  • 03-19-2012 10:04 AM In reply to

    Re: Code for multiple rows in a repeating table (VB)

    No, don't change the event handler. You need to change the code itself.

    Hilary Stoupa

  • 03-23-2012 08:51 AM In reply to

    Re: Code for multiple rows in a repeating table (VB)

    Thanks so much for your help! I got it working :)
  • 03-23-2012 08:59 AM In reply to

    Re: Code for multiple rows in a repeating table (VB)

    Hey, that's great news! Good job!

    Hilary Stoupa

  • 03-26-2012 06:48 AM In reply to

    Re: Code for multiple rows in a repeating table (VB)

    One more question... right now I have it running in a sandboxed environment. This is great but all the postbacks take a second to send data to the server. Would publishing the form via 'admin-approved' method allow the code to run in full trust without having to send it to a controlled environment?
  • 03-26-2012 04:41 PM In reply to

    Re: Code for multiple rows in a repeating table (VB)

    That's an interesting question. I'm not sure of the answer on that - I'm going to ask Anson to chime in.

    Hilary Stoupa

  • 03-26-2012 04:48 PM In reply to

    Re: Code for multiple rows in a repeating table (VB)

    I don't believe that admin approving the template will allow code to run on the client, so that won't fix the number of postbacks you are encountering.  Not sure if anyone has suggested this yet, but you can look into optimizing your form by limiting which controls will postback in the control properties browser forms tab.  If the formulas, queries, etc. need to only be run on certain actions, this is a great way to improve the performance on your form.
    Anson Hidajat
    Qdabra® Software/ InfoPathDev.com
    The InfoPath Experts – Streamline data gathering to turn process into knowledge.™

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