Iterate through a repating table - InfoPath Dev
in

InfoPath Dev

Iterate through a repating table

Last post 10-07-2008 11:43 PM by kev_wilson. 5 replies.
Page 1 of 1 (6 items)
Sort Posts: Previous Next
  • 10-07-2008 04:22 AM

    Iterate through a repating table

    Hi,

    I have a repeating table that contains a column (Price) that derives it's value from referencing a field value outside the repeating table (NumberHours). When I create a new row in the table the Price column is derived correctly. However I need to handle the situation where the user changes the number of hours which would result in a different price for each row. Is there a way I can re-evaulate the column for all rows in the repeating table when the NumberHours value is changed. i.e. iterate through each row in the table and derive the price again for the changed number of hours?

    Is it possible to do this without code? If not can anybody point me in the right direction to do this in C#

     Any help with this will be greatly appreciated.

     Cheers

    Kevin

  • 10-07-2008 05:15 AM In reply to

    Re: Iterate through a repating table

    Hi Kevin,

    How you are calculating Price column? If you are using Default vlaue in Text Box Properties window then make sure that 'Update this value when the result of the formula is recalculated' check box is checked.

  • 10-07-2008 06:41 PM In reply to

    Re: Iterate through a repeating table

    Hi Santhoshp,

    I not using the default value to populate the PriceRate column. It is currently being populated from a set of rules that are on the productItem drop down box which is in the same row in the repeating table. The product item drop down box is populated from a secondary data source that contains a list of all products and a number of colums for different day rates depending on the length of the hire of the product. e.g. 

     <ProductItem>
        <ProductItemDesc>Product 1</ProductItemDesc>
        <PriceMinSevenDays>100.00</PriceMinSevenDays>
        <PriceMinTwentyEightDays>95.00</PriceMinTwentyEightDays>
        <PriceMinTwelveWeeks>60.00</PriceMinTwelveWeeks>
      </ProductItem>

    I currently have rules for each price rate column in the dataset on the ProductItem drop down box that sets the value of the PriceRate column in the repeating table with the appropriate PriceRate depending on the number of days in the lengthofhire field (which is outside the repeating table) - each rule has a condition i.e. Length of Hire >= 0 and < 3 . The initial setting of the price rate works when you add a new product. However I want to be able to re-calculate the price rate for each product in the repeating table if the user goes back and changes the number of days (length of hire).

    Any ideas or further suggestions would be greatly appreciated. Not sure if this is possible without writing code?

    Thanks

    Kevin

     

     

  • 10-07-2008 08:18 PM In reply to

    Re: Iterate through a repeating table

    I think you may need code. Which version of InfoPath are you using? 2003 or 2007? I ask because the object models are different. In general terms, in the Changed (onAfterChange for 2003 OM) for your number of days in your length of hire field, you select the repeating group or field, and iterate through all the nodes. For example, in C# for the 2007 OM:

            public void field4_Changed(object sender, XmlEventArgs e)
            {
                XPathNodeIterator nodes = MainDataSource.CreateNavigator().Select("/my:myFields/my:group1/my:group2", NamespaceManager);
     
                foreach (XPathNavigator node in nodes)
                {
                    node.SelectSingleNode("my:field1", NamespaceManager).SetValue("new value");
                }
            }
    Hilary Stoupa

  • 10-07-2008 10:35 PM In reply to

    Re: Iterate through a repeating table

    Hi Hilary,

    Thanks for the repsonse. I was actually making some progress with another approach that you suggested in a previous blog which involved a formula in the default value which handled conditional IF logic:

    The approach is described in the the following website: http://blogs.msdn.com/infopath/archive/2006/11/27/conditional-default-values.aspx

    I can successfully select the correct column if it were based on one logic condition, for example

    concat(
    substring(xdXDocument:GetDOM("ProductItemsData")/ProductItems/ProductItem/PriceMinTwelveWeeks[../ProductItemDesc = current()/../my:ProductItem], 1, (../my:LengthOfHire >= 84) * string-length(xdXDocument:GetDOM("ProductItemsData")/ProductItems/ProductItem/PriceMinTwelveWeeks[../ProductItemDesc = current()/../my:ProductItem])),
    substring(xdXDocument:GetDOM("ProductItemsData")/ProductItems/ProductItem/PriceOneDay[../ProductItemDesc = current()/../my:ProductItem], 1, (../my:LengthOfHire < 3) * string-length(xdXDocument:GetDOM("ProductItemsData")/ProductItems/ProductItem/PriceOneDay[../ProductItemDesc = current()/../my:ProductItem]))
    )

    However I need to check if the number is > AND <.

     eg. 

    (../my:LengthOfHire > 0 AND ../my:LengthOfHire < 3)

    (../my:LengthOfHire >= 3  AND ../my:LengthOfHire < 7)

    (../my:LengthOfHire >= 7 AND ../my:LengthOfHire < 28)

    etc

    Do you know if it is possible to do AND logic using the CONCAT and Substring approach?

     Thanks in advance.

    Cheers

    Kevin

     

  • 10-07-2008 11:43 PM In reply to

    Re: Iterate through a repeating table

    Hi

    I've solved my problem. I have a working solution that does not use code but a formula in the default value for the price rate column with the "Update this value when the result of the formula is recalculated" as suggested earlier in the post. (cheers!) I applied conditional logic in the default value expression by applying the logic detailed in the following website...  

    http://blogs.msdn.com/infopath/archive/2006/11/27/conditional-default-values.aspx

    To apply the AND logic required I simply used the * (multiply) operator to multiply the result of each of the boolean conditions. If it is not true it will return 0 and true will return 1. For the condition to be true it requires 1 from each condition:  1*0 = 0, 1*1=1 :)

    Thanks for all your help with this, it has been greatly appreciated.

    Cheers

    Kevin

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