Secondary lookup fields allow users to create new, related records while entering information for a primary record. This is called adding records “on the fly” and is typically implemented for any field that also functions as a secondary lookup.
For example, when entering customer information in the Customer Maintenance window, the user can specify a salesperson ID assigned to the customer. If there’s no salesperson record associated with the salesperson ID entered, a message is displayed asking whether the user wants to create the new salesperson record.
If the user chooses to add the salesperson record, the Salesperson Maintenance window is displayed, and the key field (Salesperson ID) is set to the new ID entered in the Customer Maintenance window.
You can add records on the fly using a field change script similar to the following example. In this example, when the user enters a new salesperson ID, the change script for the ‘Salesperson ID’ field checks whether a record exists in the RM_Salesperson_MSTR table with the same key value. If not, it displays a message asking the user whether they want to add the new record.
if not empty('Salesperson ID') then {An entry was made in the field, so find out whether a record with this key value exists.} 'Salesperson ID' of table RM_Salesperson_MSTR = 'Salesperson ID'; get table RM_Salesperson_MSTR; if err()<>OKAY then {A record with this salesperson ID doesn't exist, so ask the user whether they want to create a new one.} if ask("Do you wish to add this salesperson record?", "Add", "Cancel","") = ASKBUTTON1 then {Open the Salesperson window and set the key field.} open form RM_Salesperson; 'Salesperson ID' of window RM_Salesperson of form RM_Salesperson = 'Salesperson ID' of window 'Lead Maintenance'; end if; end if; end if;