There's more...

Sometimes, it isn't possible to filter the target form, which means we must write some code on the target form to handle this.

The issue for the form is that we don't want to write a switch statement for each caller. A solution would be to write an interface that forms a code contract between the caller and the form.

After doing this, we can create an interface with the following code:

interface ConVMSVehicleGroupFilterableI
{
public ConVMSVehicleGroupId VehicleGroupId () {}
}

On the workspace, change the class declaration to the following:

public class ConVMSVehicleWorkspace
extends FormRun
implements SysIFilterProvider, ConVMSVehicleGroupFilterableI

Then, add the following method:

public ConVMSVehicleGroupId VehicleGroupId()
{
return VehicleGroupFilter.text();
}

Save and close the designers and then open the code for the ConVMSVehicleTable form. Override the init method, as follows:

public void init()
{
super();
// we don't care what the type of the calling element is, only if it is
// (or implements) our interface
if (element.args().caller() is ConVMSVehicleGroupFilterableI)
{
ConVMSVehicleGroupFilterableI filterable = element.args().caller();
if (filterable.VehicleGroupId() != '')
{
// get the instance of the query data source
// builder so we can get a query range to filter on
QueryBuildDataSource qbds =
ConVMSVehicleTable_Ds.queryBuildDataSource();
// Use SysQuery to find or create a range on the
// VehicleGroupId field
QueryBuildRange vehGroupRange = SysQuery::findOrCreateRange(
qbds, fieldNum(ConVMSVehicleTable, VehicleGroupId));
vehGroupRange.value(filterable.VehicleGroupId());
}
}
}

Save all the designers and editor tabs, and build the solution in order to test this. This is a simple example but shows how we can access the state of the caller without coupling the forms by using a switch statement based on the form's name. Even then, we would need to use the object class to call the method. This is because forms are not types that we can access in the same way as classes or tables they are definitions.