This is a simple example:
o = new Array(); o = new Object(); o.id = result._customerid_value; o.name = result['_customerid_value@Community.Display.V1.FormattedValue']; o.entityType = 'account';
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:
Alternative way of setting a lookup value with same result: