How To Create Read Only Looked Up Form Fields

Situation

You have a drop-down on a screen section and when you select the value, you want another field to fill up automatically with additional information. This information is not stored, it should be just looked, up so it can be read only.

Example

You have the following BusinessPartner entity:

Field Name Type Description
Id uniqueidentifier Primary key
Name string Customer name
FirstName string Customer first name
PhoneNumber string Customer’s phone number

Then you have another entity SalesOrder:

Field Name Type Description
Id uniqueidentifier Primary key
refBusinessPartnerId uniqueidentifier Customer
Price currency Price

You created a screen section for the SalesOrder entity where you add these fields:

  • Customer Dropdown
  • Price TextBox

Now you need a TextBox with a customer’s phone number.

Solution

The solution is to create a looked-up field in a form’s data structure, which will automatically load the values when the form loads, but also when the field value changes, e.g. while the user edits the data.

1. Create a Lookup

Create a lookup for the customer’s phone number.

  1. Select BusinessPartner entity.
  2. Right click > Actions > Create Lookup.
  3. As a Display Field select PhoneNumber.
  4. Press OK.

This will create a lookup which loads a phone number by providing a customer’s ID.

2. Create a Field In a Data Structure

Now you add the looked-up field to the form’s data structure.

  1. Go to Data > Entities and select the SalesOrder entity.
  2. Right click > New > Lookup Field.
Attribute Value Description
Field refBusinessPartnerId The field by which we will load the phone number.
Lookup BusinessPartner_PhoneNumber By this lookup the value will be looked up, so the result will be the phone number instead of the customer’s ID.
Name BusinessPartner_PhoneNumber Let’s rename the field so it indicates the content (what we take and from where).

Now we have the data source configured so it will contain a phone number. It will also automatically reload when the lookup source parameter (refBusinessPartnerId) changes so the UI does not have to care about this.

3. Add the Field To the screen section

In this last step, we will place the Phone Number field on the screen section.

  1. Open the Screen Section based on the SalesOrder entity.
  2. In the SalesOrder tab in the Toolbox select the BusinessPartner_PhoneNumber field.
  3. Change to the Widgets tab in the Toolbox, select AsTextBox/AsDateBox and drag it onto the panel.
  4. In the Properties find the (DataBindings) and expand it. The DateValue should show OrigamDataSet - SalesOrder.BusinessPartner_PhoneNumber (the SalesOrder being your current entity name and the BusinessPartner_PhoneNumber your looked-up field).
  5. Set ReadOnly to True as this field is not editable anyway.

That’s it. Now you have manually bound the text field with the looked-up field that will be provided when you execute the screen section.