For years, we all thought this was impossible. You had to use code. I somehow woke up with an idea on how to do this, and set about testing and to my surprise, found a solution. Here it is!
The form set up
- Two repeating sections, Foo's and Bar's
- One additional integer field i to control which row to copy
Put the elements on the form:
The copy rule
Create a rule on the integer field i
- We will use the normal action, then tweak it.
Give this rule the name "Copy"
Start by defining a set field value rule.
- Set /my:myFields/my:Foos/my:Foo/my:F1 to /my:myFields/my:Bars/my:Bar/my:B1
There are a few issues so far with the default Set Field Value action related to a repeating section.
- For the Field (target), it will set ALL the matching nodes.
- For the Value, it will get the First matching node.
The expression is:
This expression lets us copy a different row.
So we can now copy value from any row - depending on what the number i is.
I publish to C:\Temp\CopyForm\
<xsf:assignmentAction targetField="../my:Foos/my:Foo/my:F1" expression="../my:Bars/my:Bar[number(../../my:i)]/my:B1"></xsf:assignmentAction>
<xsf:assignmentAction targetField="../my:Foos/my:Foo[number(../../my:i)]/my:F1" expression="../my:Bars/my:Bar[number(../../my:i)]/my:B1"></xsf:assignmentAction>
- This rule is set on the number i, and runs once whenever the number i changes.
- Lets set it up to increment.
- Add a condition to stop incrementing when we've run out of rows
- And to start the whole thing, remember we have a button.
To start the process, set i to 1. XML index starts from 1 to n. Does not start at 0.
Result - InfoPath Filler
Result - Form Server:
Starting Browser Form
Note - InfoPath "Infinite Loop" limitation:
InfoPath is hard coded to only execute 16 rules before throwing the "Infinite Loop" error.
An error occurred in the form's rules or code. The number of rule actions or the number of calls to the OnAfterChange event for a single update in the data exceeded the maximum limit.
The rules or code may be causing an infinite loop. To prevent this, ensure that the rule action or event handler does not update the data which causes the same rule action or event handler to execute.
There is no solution for hard coded 16 rules. So your i can not go over 16.