SET FILTER TO FOUND()

Q:  In XDML, SET RELATION was used to set up master/detail relationships.  In addition, to limit the data so that a master record would only display if there were matching detail records, SET FILTER TO FOUND() was used.  How do you do that in the new OODML?

A:  The relationship is done by placing the two tables onto a datamodule, a form or a report, and for the detail table, you set the rowset's properties of masterRowset and masterFields. You set masterRowset to the master table, and the masterFields property to the linking field. However, this doesnot limit the display of only master rows that have matching detail rows.

To only display the master rows that have matching child rows, you have to use the canGetRow() event of the master rowset. The following code should work, but you will need to change the name of "LINKFIELD" to the name of the field you are actually using to link the two tables:

local lRet, procs
try
   procs = this.parent.parent.procs1.rowset
   if procs.setRange( this.fields["LINKFIELD"].value )
      lRet = not procs.endOfSet
   else
      lRet = false
   endif
catch ( Exception e )
   lRet = true
endtry
return lRet

You need the TRY block because the canGetRow will fire when you first assign it, and at that point, there is no PROC rowset. The CATCH should just return true to get that out of the way, otherwise it will keep trying until it finds a row.  The test uses setRange(), which is the same mechanism that the masterRowset will use, so it's slightly redundant, but there's not much you can do about it. It checks if there are any matches in the index, and if there are, whether there are any matches for the filter you have (if any).