Creating a Many-to-Many relationship in ServiceNow (2024)

PreviousNext

S

ervice-now allows you to easily create relationships between tables without having to know a whole lot about the underlying table structure. If you’ve ever worked with a reference field then you’ve worked with one of these relationships. A reference field is simply a one-to-many relationship between 2 tables in ServiceNow. The ‘one’ end of the relationship is displayed as a reference field on the form. The ‘many’ end of the relationship is displayed on the referenced table as a related list.
In some cases, it may also be necessary to create a many-to-many relationship in your instance. Because ServiceNow ships with most of these relationships already defined, it’s rare that you’ll have to create one. If you do have to create a many-to-many relationship, here’s how you could do it.

For this example, we’ll assume that we need a many-to-many relationship between the Incident and the Change request tables. One Incident can be related to many changes (maybe several changes are required as a result of an incident) and one Change request can be related to many Incidents (implementation of a change results in many incidents).

1) Navigate to the m2m table
There are two tables in your ServiceNow instance that contain many-to-many relationship information. The first one (sys_collection) contains the out-of-box relationships and should be used only for reference purposes. The second one (sys_m2m) is where you’ll want to create your own many-to-many definitions. It’s probably a good idea to create your own modules to link to these tables so that you can easily access them if you’re going to be dealing with m2m tables very often. In most cases these tables won’t be used very much so it may be easier just to navigate to them directly in the application filter in your left navigation or by navigating directly by url. The easiest way is just to type ‘sys_m2m.list’ in your left navigation filter.

Creating a Many-to-Many relationship in ServiceNow (1)

2) Create a new Many-to-Many relationship tableClick the ‘New’ button on the ‘sys_m2m’ table list and create a new record. There are really only 2 fields that you need to fill in since the rest gets automatically calculated for you. All you need to specify are the ‘From table’ and the ‘To table’ values. For this example we’ll specify ‘Incident’ as our ‘from table’ and ‘Change request’ as our ‘to table’. These values could be interchanged with no impact on the end result. You do want to pay attention to the values in the other fields though since they indicate what your table will be named along with how your related lists will be labeled. Although these are all calculated automatically, you can change them if needed.

Creating a Many-to-Many relationship in ServiceNow (2)

3) Add the related list to your Change request table

Navigate to your Change request form, right-click the form header, and personalize the related lists for the form. Select the ‘Incidents’ list to add to your form. All One-to-Many lists have a ‘->’ separating the relationship. Many-to-Many lists (and custom formatters) have no separator.

Creating a Many-to-Many relationship in ServiceNow (3)

4) Add the related list to your Incident tableFollow the same procedure for your Incident table. This list should show up as ‘Change requests’, but may show up with the name of your many-to-many table as shown below. If your related list doesn’t show up correctly, submit an incident to ServiceNow support.

Creating a Many-to-Many relationship in ServiceNow (4)

5) Relate a record to test it outYour related lists will show up at the bottom of each form. Once you have added the related lists to both sides of the relationship, it is easy to relate records to each other using the ‘New’ and ‘Edit’ buttons on the related list.

Creating a Many-to-Many relationship in ServiceNow (5)

By Crossfuze Admin|2018-07-09T15:01:30-05:00January 22nd, 2010|Categories: Relationships|Tags: Change management, Incident management, Many-to-Many, One-to-Many, Related lists, Relationships|14 Comments

Share This Story, Choose Your Platform!

FacebookTwitterRedditLinkedInEmail

About the Author: Crossfuze Admin

Creating a Many-to-Many relationship in ServiceNow (6)

Related Posts

  • Defined Related Lists

    Defined Related Lists

    July 30th, 2010|39 Comments

14 Comments

  1. Creating a Many-to-Many relationship in ServiceNow (7)

    RidiculeNovember 30, 2010 at 4:20 am - Reply

    When creating or using a M2M table, created via ‘many to many’ module or default, we see behavior that we would want to control.

    If you delete one of the records referenced, the M2M record is deleted. Sometimes you want it to happen and sometimes you don’t.

    Can someone please explain where this is happening and how can we control it, we can not find it….

    Also: the delete happening is not triggering an ‘on delete’ business rule, is the system triggering the correct delete routine?

    To see this behavior:

    Go to Many to Many, create a m2m between change an incident. connect ‘incident’ and ‘change_request’, create a record and delete one of both -> will delete the m2m record.

    Thanks for your answers!

    Rik.

    • Creating a Many-to-Many relationship in ServiceNow (8)

      Mark StangerNovember 30, 2010 at 4:42 am - Reply

      I can’t think of any time where you wouldn’t want this to happen. If the record is deleted then there is no relationship that should be shown. I did just check the ‘before delete’ rule and you’re correct there. It doesn’t run, but an ‘after delete’ rule will run. You may want to contact support about that.

      One other thing you might consider is not using the m2m table at all. For incident/change there are already reference fields that give you both ends of the common relationship between the tables. You can check out the ‘RFC’ field and ‘Caused by change’ fields on the Incident form. In my experience the use of these reference fields makes a lot more sense than a m2m table anyway.

  2. Creating a Many-to-Many relationship in ServiceNow (9)

    AjayJanuary 9, 2011 at 7:12 am - Reply

    after we create a m2m table…do we have an option to edit or delete it.

    i checked it and was unable to edit/delete…

    could any one help me with this….

    • Creating a Many-to-Many relationship in ServiceNow (10)

      Mark StangerJanuary 10, 2011 at 1:03 am - Reply

      You can edit or delete the table by opening up the table and personalizing the form (edit) or table dictionary entry (delete). You may want to contact support about the delete operation though. I put a bug in a while ago for this to be fixed, but it looks like it isn’t fully fixed yet. Right now, you can delete the table, but the m2m entry remains. The only way to delete the m2m entry is to disable the security ACL on the ‘sys_m2m’ table first. It should just be deleted when you delete the table.

      • Creating a Many-to-Many relationship in ServiceNow (11)

        AjayJanuary 10, 2011 at 11:12 am - Reply

        Thank you mark will try that and will get back to you.

        Yeah when i tried to deleted from the table dictionary entry (delete) the m2m still stay there…i was trying to just change the lable name,…but its failed…

        will try any other way to do that…thank you very much

  3. Creating a Many-to-Many relationship in ServiceNow (12)

    AndrewAugust 8, 2012 at 10:20 am - Reply

    Is there any way to audit changes of relationships established this way? Is this still the best way to set this up, or should the Related Items plugin be used?

    • Creating a Many-to-Many relationship in ServiceNow (13)

      Mark StangerAugust 8, 2012 at 10:24 am - Reply

      Auditing is kind of tricky in this situation because the operations are almost always an insert or a delete. If you want to audit these changes, then you need to set up a business rule on your m2m table to capture those changes and then store them in some other related record.

      As far as the best way, I’ve never really been a huge fan of the many-to-many task relations plugin because it’s got such a broad scope (all task types) and that makes it so that you always have to filter the information in the related list. In my experience, the cases where you need this type of functionality are generally very few and very targeted, which is why I prefer to set up my own table.

  4. Creating a Many-to-Many relationship in ServiceNow (14)

    AndrewAugust 9, 2012 at 7:59 am - Reply

    Thanks for the info Mark. When I looked at it, I didn’t exactly like the way that the plugin worked either. I think I will stick with the method you are using here.

  5. Creating a Many-to-Many relationship in ServiceNow (15)

    AkshatSeptember 5, 2012 at 10:25 pm - Reply

    HI Mark

    I have Created a Related list from Relationship under the system definitions application while displaying this as a related list on the form the edit button is not showing up… But by default every related list has a edit button

    I have also tried that from list control enable edit but i am enable to show the edit button on my related list…

    Regards
    Akshat

    • Creating a Many-to-Many relationship in ServiceNow (16)

      Mark StangerSeptember 6, 2012 at 6:21 am - Reply

      You’ll want to take a look at ACL security for that table as well. Make sure that users have create, write, and delete access.

  6. Creating a Many-to-Many relationship in ServiceNow (17)

    Dave EdgarFebruary 17, 2016 at 8:34 am - Reply

    Hi Mark

    This works well BUT what it doesn’t do is put a link on the record you have linked to. I’ll explain. I’m linking problems to problems. So for example I’m in PRB001 and link to PRB002. So PRB001 shows PRB002 in the related list but in the PRB002 record it doesn’t show PRB001 in it’s related list. Is there a way of doing this?

    • Creating a Many-to-Many relationship in ServiceNow (18)

      Mark StangerFebruary 17, 2016 at 8:56 am - Reply

      It should do exactly that. I’d guess that you don’t have the right related list associated…or maybe not the correct columns shown. If you’re relating a problem to a problem you would probably need to include both columns to show both sides of the relationship.

  7. Creating a Many-to-Many relationship in ServiceNow (19)

    DharaniJune 18, 2017 at 1:16 am - Reply

    Hi Mark,

    ITIL users cannot able to view New/Edit button in the related list.

    Any solution?

    Thanks,
    Dharani

    • Creating a Many-to-Many relationship in ServiceNow (20)

      Jim PiselloJuly 14, 2017 at 10:57 am - Reply

      Hi Dharani,

      Have you created the appropriate ACLs on the new many-to-many table to allow users with the ITIL role to create and write to records on that table?

Leave A Comment

Creating a Many-to-Many relationship in ServiceNow (2024)

FAQs

What is the problem with many-to-many relationship? ›

The problem with many-to-many relationships is that it can cause duplications in the returned datasets, which can result in incorrect results and might consume excessive computing resources.

When be set up with many-to-many relationships What is a classic example of a scenario where the tables could have many-to-many relationships ServiceNow? ›

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.

How do you handle many-to-many relationships in data model? ›

When you have a many-to-many relationship between dimension-type tables, we provide the following guidance: Add each many-to-many related entity as a model table, ensuring it has a unique identifier (ID) column. Add a bridging table to store associated entities. Create one-to-many relationships between the three tables.

Is many-to-many relations possible if not what can we do? ›

A true many-to-many relationship involving two tables is impossible to create in a relational database. I believe that is what they refer to when they say that it can't exist.

Why we should avoid many-to-many relationship? ›

Many to Many(M:N) Relationship

Many to many relationships create uncertainty and duplications on data that will eventually result in wrong statements for queries(2).

How many tables are there in a many-to-many relationship? ›

Connect the three tables to create the many-to-many relationship.

How do I add m2m table to related list ServiceNow? ›

Creating a Many-to-Many relationship in ServiceNow
  1. Navigate to the m2m table. ...
  2. Create a new Many-to-Many relationship tableClick the 'New' button on the 'sys_m2m' table list and create a new record. ...
  3. Add the related list to your Change request table.
9 Jul 2018

How do I delete a m2m relationship in ServiceNow? ›

The only way to delete the m2m entry is to disable the security ACL on the 'sys_m2m' table first.

How do you create a many-to-many relationship between two tables in ServiceNow? ›

  1. Request many to many task relations.
  2. Plugin manifest.
  3. Define a relationship type.
  4. Define a task relationship allowed from the task relationship type record.
  5. Modify the displayed field.
  6. Mark as Solution button.
  7. Define task relationships with UI actions.
4 Aug 2022

What is primary key in many-to-many relationship? ›

In a many-to-many relationship, a row in table A can have many matching rows in table B, and vice versa. You create such a relationship by defining a third table that is called a junction table. The primary key of the junction table consists of the foreign keys from both table A and table B.

What is a one-to-many relationship explain using an appropriate example? ›

In a one-to-many relationship, one record in a table can be associated with one or more records in another table. For example, each customer can have many sales orders.

How many relationships are possible between two tables or entities? ›

There are three types of relationships that can exist between two tables: one-to-one. one-to-many. many-to-many.

When mapping a many-to-many relationship it must first be resolved using? ›

This is Expert Verified Answer

The best way to resolve an m:n relationships will be to take out the two entities and make two one-to-many (1:n) relationships amongst them along with a third entity that is intersecting. The intersecting entity may have attributes of both the connecting entities.

What is the difference between one-to-many and many to one relationship? ›

For example, if one department can employ for several employees then, department to employee is a one to many relationship (1 department employs many employees), while employee to department relationship is many to one (many employees work in one department). Save this answer.

What are many-to-many relationship fields in ServiceNow? ›

Many-to-many (M2M) relationships are similar to one-to-many relationships, except that they aren't usually dependent on a foreign key column in a child table. Instead, many-to-many relationships in ServiceNow usually rely on an intermediary table called an M2M table.

Top Articles
Latest Posts
Article information

Author: Gov. Deandrea McKenzie

Last Updated:

Views: 5967

Rating: 4.6 / 5 (66 voted)

Reviews: 81% of readers found this page helpful

Author information

Name: Gov. Deandrea McKenzie

Birthday: 2001-01-17

Address: Suite 769 2454 Marsha Coves, Debbieton, MS 95002

Phone: +813077629322

Job: Real-Estate Executive

Hobby: Archery, Metal detecting, Kitesurfing, Genealogy, Kitesurfing, Calligraphy, Roller skating

Introduction: My name is Gov. Deandrea McKenzie, I am a spotless, clean, glamorous, sparkling, adventurous, nice, brainy person who loves writing and wants to share my knowledge and understanding with you.