How to add a lookup to another table
Link opportunities to accounts with a lookup field, pick an account on a record, and find the opportunity again from the account's Related tab. How-to video H020, step by step.

How-to H020 · 2 min 4 s. A complete tutorial: every click and value the video uses, the relationship the lookup creates, and how a script follows it in both directions. Every picture is a frame of the video.
A lookup links one record to another: an opportunity to the account it is for. In this tutorial you add an Account lookup to Opportunity, pick an account on a record, and then find the opportunity again from the account's side.
Before you start
- The Opportunity table in Sales Tracker, from How to add a field to a table, and the Sales Tracker app.
- An opportunity to link: Contoso fleet renewal.
- An account to link it to. Every environment starts with the Account and Contact tables. The video uses an account called Contoso Group. If your environment has no accounts, create one under Accounts once Part 3 has added them to the app.
Which side the lookup goes on
One account has many opportunities. Each opportunity has one account. So the lookup goes on Opportunity, the many side: each opportunity holds the one account it belongs to.
| Table | What it gets |
|---|---|
| Opportunity | An Account field: one account per opportunity. |
| Account | A Related › Opportunities list: every opportunity that points at it. |
Part 1: Add the lookup
-
Open Solutions, then Sales Tracker, select Tables and open Opportunity.
-
Select New and fill in the panel:
Box Value Display name AccountLogical name (fills itself in) tsp_accountData type Lookup Related table Type accand pick AccountRead the note under the data type: saving the lookup also creates its relationship.

- Select Save. The field's type reads Lookup to account.
- Select Relationships. The relationship is already there, named from the table and the field:
tsp_opportunity_tsp_account. There was no separate step.
Part 2: Put it on the form
- Select Forms and open Information.
- Drag Account in, under Name, and select Save.
Part 3: Show accounts in the app
An account lists its opportunities only in an app that shows accounts.
- In the solution, select Apps and open Sales Tracker.
- Under the Sales group, select the add-table button, pick Account, and select Save.
Part 4: Link a record
- Open Sales Test's address, open Sales Tracker and open Contoso fleet renewal.
- The Account field is a search box. Type
Contoso. It matches as you type. - Pick Contoso Group.
- Select Save & Close.
Part 5: See it from the other side
- Select Accounts in the app's navigation, search for Contoso Group and open it.
- Select Related, then Opportunities.
Contoso fleet renewal is listed, because its account is this one.

The lookup as text
The field names the table it points at:
{ "logicalName": "tsp_account", "displayName": "Account", "dataType": "Lookup", "targetEntity": "account" }
And the table's document gains the relationship it created:
{
"logicalName": "tsp_opportunity_tsp_account",
"type": "OneToMany",
"referencedEntity": "account",
"referencingEntity": "tsp_opportunity",
"lookupField": "tsp_account"
}
One account (the referenced table) to many opportunities (the referencing table), through the
tsp_account field. The column has a real foreign key, so it can only hold an account that exists.
Following the lookup in a script
A lookup holds the linked record's id. From an opportunity to its account, in BS Lang:
var opp = getRecord("tsp_opportunity", getRecordRef("record"));
var account = getRecord("account", opp.tsp_account);
And from an account to all its opportunities, the same question the Related tab asks:
var opportunities = runQuery({
entity: "tsp_opportunity",
filter: {
connector: "And",
conditions: [
{ field: "tsp_account", operator: "Equals", value: getRecordRef("record") }
]
}
});
If something goes wrong
- The account has no Related › Opportunities. The app doesn't show accounts, or you opened the account in a different app. Check Part 3.
- The search box finds nothing. There is no matching account, or your role can't read accounts.
- You picked the wrong related table. A lookup's table can't change after saving, because its column and foreign key point at it. Delete the field (which removes its relationship too) and add it again under a new name.
What you built
The link, and its other end: one field on Opportunity, a relationship, and a list on every account of the opportunities that point at it, with nothing extra to build.
Read more
- The help page: Add a Lookup to Another Table, the page this screen's Help link opens.
- The feature, explained: Lookups in Parsware: linking one record to another.
- The next how-to: How to add a lookup that points at several tables.
- Every how-to: the How-tos category.
Is there a task you would like to see done step by step? Tell us. parsware.com/contact