Many-to-many relationships
Quick answer
Model relationships that are not simple references: m2m tables, related lists and when to use a relationship record.
Key takeaways
- m2m definitions generate the join table and both related lists
- One row per pair keeps the model clean and reportable
- Defined relationships handle computed lists a join cannot express
- Relationship queries run on every form load, keep them cheap
Why a reference is not enough
A reference field holds one value. When an incident can affect many CIs and a CI can be affected by many incidents, you need a join table with a reference to each side. The platform calls this a many to many definition and generates the table and related lists for you.
Creating one
Use System Definition, Tables and Classes, Many to Many Definitions. Give it the two tables and labels for each direction. The generated table holds one row per pair, and both sides get a related list.
Relationship records
For lists that cannot be expressed as a simple join, use a defined relationship (sys_relationship) with a query script.
- Relationships can show records from any table using your own query
- They appear as related lists you can add through form design
- Keep the query efficient, it runs every time the form opens
- Prefer m2m tables where the data really is a pair, relationships are for computed lists
Want to learn this properly?
Our live, instructor-led ServiceNow Training covers this hands-on, with real projects and a certification path.
Check your understanding
What does a many to many definition create?
- A. A database view
- B. A join table plus two related lists
- C. A dictionary override
- D. A transform map
Show answer
B. A join table plus two related lists
The definition generates the table and related list configuration.
When is a defined relationship the better tool?
- A. When pairing two records
- B. When the related list needs a custom query
- C. When reporting
- D. When importing data
Show answer
B. When the related list needs a custom query
Relationships run a script to build lists a join cannot express.