Set field to initial value or from previous row's field. - InfoPath Dev
in

InfoPath Dev

Set field to initial value or from previous row's field.

Last post 02-11-2013 01:41 PM by DavidM. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 02-09-2013 10:50 AM

    • DavidM
    • Not Ranked
    • Joined on 01-24-2013
    • Posts 2

    Set field to initial value or from previous row's field.

    Hi,

    My first newbie question. I have an Infopath 2010 form with repeating table group2 containing field1, 2, 3,

    and 4. Group2 is nested in another repeating table group4 that also contains field5. Field5 has an initial

    value used to set field2 if field2 is on the first row of the nested table.

    /my:myFields
       /my:group3
          /my:group4 - repeating table
             /my:field5
             /my:group1
                /my:group2 - repeating table
                   /my:field1
                   /my:field2
                   /my:field3
                   /my:field4

    Field1 has the default value formula:

     count(../preceding-sibling::my:group2/my:field1) + 1

    This works correctly to return the row number of the nested table.

    Field4 has the default value formula:

     field2 - field3

    Field2 has the default value formula:

     ../../my:field5 | ../preceding-sibling::my:group2[1]/my:field4[(../my:field1 < 1) + 1]

    This is not working correctly as it only returns the initial value from field5 no matter what the row number

    is. I need the field5 value returned for the first row, but otherwise I need the value from field4 of the

    previous row.


    A variation of this formula works correctly on a different, but similar Infopath form that has a repeating

    table with fields1, 2, 3, and 4, but in this case the table is not nested in another repeating table. Field5

    exists outside the one repeating table.

    /my:myFields
       /my:field5
          /my:group1
             /my:group2 - repeating table
                /my:field1
                /my:field2
                /my:field3
                /my:field4

     ../../../my:field5 | ../preceding-sibling::my:group2[1]/my:field4[(../my:field1 < 1) + 1]


    Thank's for any help with this.

  • 02-09-2013 03:48 PM In reply to

    Re: Set field to initial value or from previous row's field.

    Hi David and welcome,

    First off, please make sure you name your data source fields and groups to be something that is descriptive as it will save you a major data map headache later when you want to report on the data in the XML.

    Secondly, you shouldn't be using group2[1] to index field4. You need to move the [] filter for field 4 [(../my:field1 < 1) + 1] to group2 and filter that based on that sine that's the repeater. I don't quite understand what you are trying to do with the (../my:field1 < 1) condition, but this also seems wrong. My hunch is that you should be using current()/my:field1 to get that.

    Hope this steers you in the right direction. Please let us know what you get working.

    Patrick Halstead
    Project Manager at Qdabra
  • 02-11-2013 01:41 PM In reply to

    • DavidM
    • Not Ranked
    • Joined on 01-24-2013
    • Posts 2

    Re: Set field to initial value or from previous row's field.

    Hi,

    I seem to have this working now with the following:

    /my:myFields
       /my:group3
          /my:Repeating_Category_Table
             /my:group1
                /my:Original_Category_Balance (for this example, a hard-coded value)
                /my:Repeating_Balance_Table
                   /my:Initial_Balance (hidden)
                   /my:Starting_Row_Balance
                   /my:Pending_Approval
                   /my:Ending_Row_Balance


    Initial_Balance has the default value formula:

       ../../my:Original_Category_Balance

    Starting_Row_Balance has the default value formula:

       ../my:Initial_Balance[count(.) = 1] | ../preceding-sibling::my:Balance_Table[1]/my:Ending_Row_Balance[count(.) > 0]

    This returns the value from Initial_Balance if the count of occurrances is = 1, otherwise it returns the

    value from Ending_Row_Balance of the previous row if the count of occurrances is > 0.


    I would prefer to reference the Original_Category_Balance field rather than have to populate the

    Initial_Balance field in each row, but have not been able to get that to work.

    Ending_Row_Balance has the default value formula:

       ../my:Starting_Row_Balance - ../my:Pending_Approval

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