You have a drop-down on a form 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.
You have the following BusinessPartner entity:
|FirstName||string||Customer first name|
|PhoneNumber||string||Customer's phone number|
Then you have another entity SalesOrder:
You created a Screen Section for the SalesOrder entity where you add these fields:
- Customer Dropdown
- Price TextBox
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.
- Select BusinessPartner entity.
- Right click > Actions > Create Lookup.
- As a Display Field select PhoneNumber.
- 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.
- Go to Data > Entities and select the SalesOrder entity.
- Right click > New > Lookup Field.
|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 Form
In this last step we will place the Phone Number field on the form.
- Open the Screen Section based on the SalesOrder entity.
- In the SalesOrder tab in the Toolbox select the BusinessPartner_PhoneNumber field.
- Change to the Widgets tab in the Toolbox, select AsTextBox/AsDateBox and drag it onto the panel.
- 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).
- 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 form.