A script-enabled browser is required for this page to function properly.

Populating an Item with Values from another Table

To populate an item with values from another table:

  1. Create an item of the desired type in the appropriate data block.
  2. Double click the item to display the Property Palette.
  3. Under the Database node, set the Database Item property to No to make the item a control item.
  4. Under the Data node, set the Data Type, Maximum Length, and any other properties needed to be compatible with the type of fetched values the item will display.
  5. Create triggers to populate the control item at runtime.

About populating items with values from other tables: Example

A Post-Query trigger fires when the operator or the application executes a query. It fires once for each record fetched, which means that your code inside the trigger can read and set the values of values in each record.

To populate a control item named CUSTOMER_NAME in a data block named ORD_BLK, you could create the following Post-Query trigger attached to the ORD_BLK block.

Post-Query Trigger for ORD_BLK block:  

   SELECT name 
   INTO :ord_blk.customer_name 
   FROM s_customer 
   WHERE s_customer.id = :ord_blk.customer_id;

The Post-Query trigger takes care of retrieving the customer name when the operator queries orders in the block, but you also need to display the customer name when the operator is entering or updating the customer ID item during data entry. To handle this task, create a When-Validate-Item trigger attached to the customer ID item.

A When-Validate-Item trigger fires when the operator or the application navigates out of the item, and gives you the opportunity to issue a SELECT statement that populates the Customer_Name item.

When-Validate-Item Trigger for Customer ID item:

BEGIN 
   SELECT name 
   INTO :ord_blk.customer_name 
   FROM s_customer 
   WHERE  s_customer.id = :ord_blk.customer_id;
EXCEPTION 
WHEN  NO_DATA_FOUND THEN Message('Invalid Customer ID. Please enter again.'); RAISE Form_Trigger_Failure; END;

 


About populating items with values from other tables

Creating a Data Item

About Triggers and Events