Using Rules to Update Fields in a Table Row - Greg Collins
in

InfoPath Dev

This Blog

Syndication

Greg Collins

Using Rules to Update Fields in a Table Row

While working today on my example form, Populating Table Row After Selection (Rules), I had an epiphany—a possible way of accomplishing this without resorting to manually editing the XSL or using code.

The concept was to create a Support secondary data source with a RowPosition node who's soul purpose was to store the current row.

In the table row existed a drop-down list box and a series of other fields. When the selection changed in the drop-down list box, the other fields should be updated with the correct values from a SQL database. Here's what I did:

When the selection changed, I fired a series of rules to populate the table row fields with the corresponding SQL database fields, filtered on the selection made in the drop-down list box. This works great for a single table row, but not so good for multiple rows.

By adding an initial rule which sets the value of the RowPosition node in the Support DOM with the value of the XPath function count(../preceding-sibling::my:RowNode) + 1, I now have a reference to the current table row.

At this point I updated each of the other rules to make use of the RowPosition node. Here's a before and after of one particular rule with the difference highlighted:

BEFORE:

xdXDocument:GetDOM("Customers")/dfs:myFields/dfs:dataFields/d:Customers/@CompanyName[../@ContactName = xdXDocument:get-DOM()/my:myFields/my:Customers/my:Customer/@my:Name]

AFTER:

xdXDocument:GetDOM("Customers")/dfs:myFields/dfs:dataFields/d:Customers/@CompanyName[../@ContactName = xdXDocument:get-DOM()/my:myFields/my:Customers/my:Customer[xdXDocument:GetDOM("Support")/Support/RowPosition]/@my:Name]

With the addition of storing the current row and the change to the XPath for setting the field values, I was sure it would work. But, alas, it didn't. It didn't take long to figure out why. My initial guess was correct. The RowPosition was being filled in as a string. By making one more adjustment, and forcing it to be a number, the solution worked beautifully! Here's the final working version:

FINAL:

xdXDocument:GetDOM("Customers")/dfs:myFields/dfs:dataFields/d:Customers/@CompanyName[../@ContactName = xdXDocument:get-DOM()/my:myFields/my:Customers/my:Customer[number(xdXDocument:GetDOM("Support")/Support/RowPosition)]/@my:Name]

There are other issue to tackle too, such as having a drop-down list box in each row of a table can quickly become a huge performance hit. If you are using a Master-Detail table, you can move the drop-down list box into the Detail table. This will certainly help as you will then only have a single source for the list instead of one per row.

©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.