m2m table vs. list field for many-to-many relationships

Max Nowak
Kilo Sage

Hi,

I'm curious about the potential advantages / drawbacks of using list (glide_list) fields, or m2m tables, to facilitate many-to-many relationships.

 

To me, both provide similar functionality, but in a different way. For example, a m2m table record will show up on both referenced tables, while a list would only show up on the table with the list field, not on the records referenced in that list. Both seem to provide the functionality of connecting multiple records with one another.

 

What would be some potential use-cases where I would use one over the other?

 

Thanks,

Max

1 REPLY 1

Kratika Chowdha
ServiceNow Employee
ServiceNow Employee

 

The Guide to Many-to-Many Relationships in ServiceNow

 

In ServiceNow development, modeling many-to-many (M2M) relationships is a common architectural decision. Whether linking users to configuration items or incidents to problems, the platform offers two primary tools for the task: the glide_list field and the dedicated many-to-many (M2M) junction table.

Neither tool is inherently "better" than the other; they are different solutions designed for different problems. A choice that seems simple at the dictionary level can have significant long-term impacts on reporting, performance, and maintainability. This guide provides an objective, architectural comparison to help you select the appropriate tool based on the specific requirements of your business use case, from simple data storage to complex, logic-driven applications.


 

Understanding the Glide List

 

A glide_list is a specialised field type that provides a quick way to create a multi-select capability on a form. It's essential to understand its underlying structure to know when and where to use it effectively.

Technical Foundation:

At the database level, a glide_list field stores its data as a single, comma-separated string of sys_ids in a VARCHAR or TEXT column.1 The most common out-of-the-box example is the Watch list field on the Task table, which stores a list of user sys_ids for notification purposes.

When to Consider a Glide List:

The glide_list shines in scenarios where speed of implementation is a priority and the functional requirements are simple.

  • Rapid Development: A glide_list can be configured in the dictionary in moments, making it ideal for prototypes or simple requirements where a multi-select UI is needed without complex downstream logic.

  • Simple Data Association: For use cases like adding informational "tags" to a record or managing a simple notification list (like the watch list), a glide_list is often sufficient. The key condition is that the data is for display or simple reference and not intended to be a primary driver for reporting or business rules.

  • Data Staging: During data imports via Transform Maps, a glide_list can serve as an effective temporary field to hold multiple values before a script processes them into a more structured format.

Architectural Considerations:

When choosing a glide_list, it's important to be aware of the technical trade-offs that come with its string-based storage.

  • Scripting: Programmatic interaction requires string manipulation. Developers must split the comma-separated string into an array to perform logic (like adding or removing a value) and then join it back. This often leads to the creation of helper utilities, like a ListUtil script include, to manage these operations consistently.  ListUtil

  • Query Performance: Searching a glide_list requires a CONTAINS or LIKE operator, which can lead to full table scans. On tables with large record counts, these queries can become a performance bottleneck.

  • Reporting Limitations: The reporting engine treats the entire string as a single value. This makes it impossible to group a report by the individual items within the list, as each unique combination and order of sys_ids is considered a distinct group. Workarounds exist, such as using a "shadow" table populated by a business rule, but this effectively means building a manual M2M table to make the glide_list reportable.

  • No Dot-Walking: It is not possible to dot-walk through a glide_list field. This is a critical limitation if you need to build logic (like a reference qualifier or a business rule condition) based on the attributes of the records stored in the list. Such requirements necessitate scripted workarounds to query the referenced records separately.


 

Understanding the M2M Junction Table

 

The junction table is the standard, relational database approach to modeling a many-to-many relationship. It is a robust and scalable solution that is fully supported by the ServiceNow platform's architecture.

Technical Foundation:

An M2M relationship is created using an intermediary table that contains two reference fields, each linking to one of the tables in the relationship.The sys_user_grmember table, which connects Users and Groups, is a perfect example. Each record in this table represents a single, distinct relationship between one user and one group.

When to Choose an M2M Table:

The M2M table is the preferred solution for enterprise-grade applications that require scalability, powerful reporting, and the ability to drive complex business logic.

  • Enterprise Data Modeling: For core business objects like CMDB relationships (cmdb_rel_ci) or user entitlements (sys_user_has_role), the M2M table provides the necessary data integrity and performance.

  • Robust Reporting and Analytics: Data in M2M tables is fully reportable. You can group, sort, and filter by either side of the relationship. For advanced needs, junction tables can be joined with other tables using Database Views to create powerful, multi-table reports.

  • Driving Business Logic: When you need to make decisions based on the attributes of related records, the M2M table is the correct choice. It allows for efficient querying to support workflows, business rules, and other automations.

  • Storing Relationship Metadata: Because the junction table is a true table, you can add extra fields to it to store data about the relationship itself (e.g., when a relationship was created, who created it, or the status of the relationship). This is impossible with a glide_list.

Architectural Considerations:

The primary trade-off for the power of an M2M table is a slightly more involved setup process.

  • Initial Setup: Creating an M2M table is best done using the platform's System Definition > Many to Many Definitions module. This process involves a few more steps than creating a single field, but it correctly configures the table, reference fields, and related lists. Tables created this way are also typically exempt from custom table licensing.

  • Access Control: Custom M2M tables require manual creation of Access Control Lists (ACLs) to grant non-admin users the ability to read, create, and write records, which enables the "Edit..." button on the related list. This is a one-time configuration that ensures the relationship is properly secured.


 

A Framework for Making the Right Choice

 

As an architect or developer, ask the following questions when deciding between a glide_list and an M2M table:

  1. What are the reporting requirements?

    • If the answer is "none," or "only filtering the list as a whole," a glide_list may be sufficient.

    • If you need to group reports by individual items in the list or create complex analytics, an M2M table is required.

  2. Will this relationship drive business logic?

    • If the list is purely informational, a glide_list is a viable option.

    • If you need to dot-walk to access attributes of the related records for use in conditions, reference qualifiers, or scripts, you must use an M2M table.

  3. What is the expected data volume and query frequency?

    • For small, infrequently queried tables, the performance impact of a glide_list may be negligible.

    • For large, frequently queried tables (like Task or CMDB), the indexed queries of an M2M table are essential for maintaining instance performance.

  4. Do I need to store data about the relationship itself?

    • If the answer is yes, an M2M table is your only option.


 

The Architect's Verdict

 

The choice between a glide_list and an M2M table is a classic architectural trade-off between short-term implementation speed and long-term scalability and functionality.

  • The Glide List is a tactical tool, perfectly suited for simple, non-critical use cases where reporting and complex logic are not requirements. Its speed of setup makes it a valuable option for rapid development when its limitations are understood and accepted.

  • The Junction (M2M) Table is a strategic foundation. It aligns with proven database principles and unlocks the full power of the Now Platform's reporting, automation, and security features. It is the standard for building robust, scalable, and maintainable applications.

By evaluating your business requirements against the architectural characteristics of each tool, you can confidently make the right choice, ensuring your solution is not only functional today but also prepared for the demands of tomorrow.