Identify the Current Table Row - Greg Collins
in

InfoPath Dev

This Blog

Syndication

Greg Collins

Identify the Current Table Row

If you are trying to identify the current table row so that you can make modifications to other field in that row, the safest thing to do is to make those modifications using code. This will be the fastest (performance-wise) solution. You can see how this is done by playing with my example form: Populating Table Row After Selection (Code).

But if you absolutely do not want to touch code, you can do this with Rules and a node to hold the current row position. This RowPosition node should be located in a secondary data source so as to not dilute your main DOM. The concept is simple.

Let's assume you have an XML structure, using the "my" namespace, that is organized like the following:

    People
        Person
            Name
                First
                Last
            Address
            Phone
            Email

Let's also assume that we have a secondary data source named Support that is organized like the following:

    Support
        RowPosition

You would create a Rule on the desired node, in this example, we'll use Phone. The Rule will set the value of the RowPosition node, in the secondary data source, to the XPath function count(XPath_To_Repeating_Row_Node) + 1. In this case the XPath would be ../preceding-sibling::my:Person. Why my:Person? Because that is the actual "row" of the table. That is the repeating node. So if we were to place the Rule on my:First, we would have to modify the function to include an additional axis specifier (i.e. another "../"). The resulting XPath would then be ../../preceding-sibling::my:Person.

This will work even when filters or conditional formatting are used to hide certain rows.

Once you have the row position saved, you can use it to get direct access to your row for making updates to other fields. You do this by modifying the XPath of each Rule that updates another field on the row. In the case of our example XML structure above, you would locate my:People/my:Person/... in the XPath and modify it to include the specified row. It would now look like: my:People/my:Person[number(xdXDocument:GetDOM("Support")/Support/RowPosition)]/... .

You must specify the XPath number() function or this technique will not work.

©2004 Greg Collins. All rights reserved. Licensed to Autonomy Systems, LLC for display on InfoPathDev.com.

Comments

No Comments
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.