Development

Many-to-Many Relationship

There are three ways to relate tables in ServiceNow. A one-to-one relationship would be used when a record from one…

There are three ways to relate tables in ServiceNow. A one-to-one relationship would be used when a record from one table is related to one record in another table. An example of this would be in a school database, each student is assigned an ID and each ID is only assigned to one student. A one-to-many relationship is when one record in a table is related to many records in another table. For example, if we had a table of customers, each customer could be related to many sales orders. Finally, we can create a many-to-many relationship. A many-to-many relationship is when many records from one table are related to many records in another table. An example of this would be a customer can purchase many products and products can be purchased by many customers. I am going to show you in the steps below how to create a many-to-many table in ServiceNow.

  1. First navigate to the m2m table. You can navigate to this table by typing “sys_m2m.list” in your left navigation filter.

ServiceNow App Engine Studio page with 'sp_m2m.do' highlighted.

  1. Create a new Many-to-Many relationship table. Click the “New” button on the “sys_m2m.list” list to create a new record. The only fields you need to fill are the “From table”, “To table”, and “Many to Many table” fields. The other fields will automatically fill but can be changed if needed. I recommend filling the “Many to Many table” field with a unique name for your reference.

ServiceNow Many to Many Definitions list with a red arrow pointing to the 'New' button.

Many-to-Many Definition form with 'From table', 'To table', and 'Many to Many table' fields filled.

  1. Add the related list to your table, in this example it is the “Products” table. Click on a record within the table. If there is not one, create it. Once you are in a record, right-click in the banner and navigate to Configure->Related Lists.

ServiceNow UI: Context menu open on 'Products' record, 'Configure' expanded, 'Related Lists' highlighted.

Next, highlight the table you would like to add and select the “>” to add the table.

Configuring related lists on Products form. Available: Attachments, Customers. Selected: empty.

Once you click “Save” you will be navigated back to the “Products” table. You should see the related list now.

ServiceNow UI: Products record with 'Customers' related list tab highlighted.

  1. Relate a record to test. At the bottom of the “Products” table, click “New” next to “Customers.”

ServiceNow Products page with Customers related list. Red arrow points to the 'New' button.

After you submit the new record, you should see the record in the related list and the “Customers” table.

Products table with a red arrow pointing to a customer record ID.

ServiceNow Customers table with a red arrow pointing to a record's creation date.

Now you have created a many-to-many relationship.