This is a simple example:
The lookup value retrieved is an object and to get each component is shown in the image above. This is the main difference between a regular field e.g. text field and a lookup field, a text field will simply return the text value where the lookup field returns an object. Some small but important components are required when getting the field value. These are that the field is on the form and that the field doesn’t return null, so it’d be wise having a null check.
Setting a lookup value: