IT CanvassTalk to an advisor
Data model · LessonBy , ServiceNow Architect · Published · ServiceNow · all levels

Many-to-many relationships

Model relationships that are not simple references: m2m tables, related lists and when to use a relationship record.

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

Practice challenge

+0 XPStreak ×0
Question 1 of 2
What does a many to many definition create?

Frequently asked questions

Can I report across an m2m table?
Yes. Report on the join table and dot-walk to fields on both sides, or build a database view when you need a flattened result.
Why not add ten reference fields instead?
Because the number of related records is unbounded and unreportable. A join table scales, ten fields do not.
Already working on ServiceNow and stuck on a live ticket?Get an expert ServiceNow developer on screen-share to finish your daily tasks with you. Deliver on time, protect your reputation and your job. Monthly support only, no task-wise plans.Task assigned · no idea where to startStill stuck · your job on the lineExpert joins your screenDelivered on timeExplore On Job Support