Set the default value of the destination field to the following XPath formula (making the appropriate modifications), but don't check "Update this value when the result of the formula is recalculated." This will set that destination node to the appropriate value when the form loads.
/my:myFields/my:group1/my:group2[position() = xdXDocument:GetNamedNodeProperty(/my:myFields/my:group1, "CTRL1_5", 1)]/my:field2
Here
-
/my:myFields/my:group1/my:group2 is the repeating node
-
/my:myFields/my:group1 is the node that contains the repeating node
-
CTRL1_5 is the value of the ViewContext property of the repeating table (you can find this value by viewing the repeating table's properties and looking at the Advanced tab)
-
my:field2 is the child of my:group2 that you want to copy to the destination field
Then adding a Context Change event to your form with code like the following should take care of the rest:
public void FormEvents_ContextChanged(object sender, ContextChangedEventArgs e)
{
if (e.ChangeType == "ContextNode")
{
XPathNavigator repeatingNode = e.Context.SelectSingleNode("ancestor-or-self::my:group2", NamespaceManager);
if (repeatingNode != null)
{
XPathNavigator destinationNode = repeatingNode.SelectSingleNode("/my:myFields/my:outsideField", NamespaceManager);
destinationNode.SetValue(repeatingNode.SelectSingleNode("my:field2", NamespaceManager).Value);
}
return;
}
}
Again, my:group2 is the repeating node, /my:myFields/my:outsideField is the destination node, and my:field2 is the field whose value I want to copy.
That should work for most situations.