In this post I describe how to override and existing standard lookup. Example see form VendorTable tab General, here see the field ‘Group’ which is based on a lookup from the VendGroup table. (control name is formcontrol Posting_Vendgroup). In this example we are going to redesign this lookup, so that we not only see information from table VendGroup (fields VendGroup and Name), but also information from a second table Payment methods payment, (table PaymTerm ( fields Days and PaymMethod). I show you how to link VendGroup and PaymTerm table which are used in the lookup.
In this lookup I also have build a filter so that we can filter out the vendor groups which are marked with a the field ‘One-time vendor’, which is not a standard field in the VendGroup table, but an extension. Our aim is that once a record is marked as ‘One-Time vendor’, it will not taken into consideration in the lookup if the vendor (caller record) is not a One-time vendor.
If we run the lookup in the standard situation, and we select a vendor who is not a One-time vendor, we see the following result (without One-time vendor filtering):
I will demonstrate how to write the lookup code from scratch and and how to cancel the call to the standard lookup with cancelSupercall().
Lookup formcontrol name is “Posting_VendGroup”, you can find control name by select the control and right mouse click. A dialog appears. Select option “Form information”.
Right click formcontrol Posting_VendGroup, select “OnLookup” and select option “Copy event handler method”.
Paste it in a new or existing class:
As mentioned earlier, the lookup information is collected from two tables, VendGroup and PaymTerm. We are going to build our lookupcode, we are using the SysTableLookup class. This class has a limitation that we cannot use multiple table for it. Therefore we need to create a view.
In the view we can use the two tables as datasources, as demonstrated in the screenshot below:
Note: Because we have extend table VendGroup (add new field One-time-vendor) it’s recommendable not only to build your model (key combination ctrl-R ctrl-B) and tick select in tab options build cross reference data + synchronize database (second screenshot below), but in tab ‘packages’ also select option ‘Build referenced packages [models] before going to the next step. (see screenshot below)
In line 20 we see the logic for filtering vendorgroups marked as ‘One time-vendor’.
Now we can write the logic for the lookup. We are using the SysTableLookup class, and make our own query object. Note Use NoYes enum instead of Boolean for the ‘One-time vendor’ range.
In line 31 and 32 we are canceling the call to the standard lookup, by using the FormControlCancelSuperEventArgs class.
If we run the lookup now it looks like this:
If we check the vendor groups, we indeed see that records marked as ‘One-time vendor’ are not selected.