Can we aply One Relationship on multiple Tables

SriVasanthV
Tera Contributor

for an example , if we want to see related records for particular incident , we can do it.
in sameway can we apply one relationships on multiple tables

queries from 1 table 
applies to multiple tables

please clarify

 

Thank You

1 ACCEPTED SOLUTION

DiveshTyagi
Mega Guru

Hi @SriVasanthV ,

 

You cannot directly apply a single “relationship” definition across multiple tables in ServiceNow. Relationships (defined in the sys_relationship table) are scoped to a pair of tables. If you want similar related lists across multiple tables, you either need to define separate relationships for each table or use a scripted relationship that dynamically queries based on context.

 

How Relationships Work in ServiceNow:

  • One-to-Many: A reference field links one record to many records in another table (e.g., caller_id on Incident → User table).
  • Many-to-Many: Uses a mapping table to connect records from two tables (e.g., Groups ↔ Users).
  • Scripted Relationships: Custom logic that defines how related records are fetched, not limited to direct references.

Each relationship is stored in the sys_relationship table and is tied to specific tables. That’s why you can’t “reuse” one relationship definition across multiple tables without creating additional entries.

 

------------------------------------------------------------------------------------------------------------------------------------------------

Example Scenario

Requirement: Show related records (e.g., Tasks) for multiple parent tables like Incident, Problem, and Change.

Standard Approach

  • Create a relationship for Incident → Task.
  • Create another for Problem → Task.
  • Create another for Change → Task.

Each relationship is defined separately, even if the query logic is similar.

Scripted Relationship Approach

You can define one scripted relationship that dynamically checks the parent table and returns related tasks:

 

(function executeRelationship(current) { 
var gr = new GlideRecord('task'); 
gr.addQuery('parent', current.sys_id);
gr.query();
 })(current);

This script can be reused, but you still need to configure it for each table where you want the related list to appear.

 

References:

 

 

-------------------------------------------------------------------------------------------------------------------------------------------------

If my response helped, please mark it as the accepted solution so others can benefit as well.

Regards,

Divesh Tyagi

 

View solution in original post

2 REPLIES 2

prerna_sh
Tera Sage

Hi @SriVasanthV 
Yes, there is a "one-to-many" relationship you can define for you use case.

Checkout the below threads:
One-to-Many Relationships in ServiceNow - Inabia Software & Consulting Inc
Solved: Need advice on creating one to many relationship b... - ServiceNow Community
Solved: Create One to Many Relationship - ServiceNow Community
https://youtu.be/1gNIT_NXU7U?si=fkxUESerfXRMMeXZ
-------------------------------------------------------------------------------------------------------------------------------------------
If my response solves your query, please marked helpful by selecting accept as Solution and Helpful. Let me know if anything else is required.
Thanks,
Prerna

DiveshTyagi
Mega Guru

Hi @SriVasanthV ,

 

You cannot directly apply a single “relationship” definition across multiple tables in ServiceNow. Relationships (defined in the sys_relationship table) are scoped to a pair of tables. If you want similar related lists across multiple tables, you either need to define separate relationships for each table or use a scripted relationship that dynamically queries based on context.

 

How Relationships Work in ServiceNow:

  • One-to-Many: A reference field links one record to many records in another table (e.g., caller_id on Incident → User table).
  • Many-to-Many: Uses a mapping table to connect records from two tables (e.g., Groups ↔ Users).
  • Scripted Relationships: Custom logic that defines how related records are fetched, not limited to direct references.

Each relationship is stored in the sys_relationship table and is tied to specific tables. That’s why you can’t “reuse” one relationship definition across multiple tables without creating additional entries.

 

------------------------------------------------------------------------------------------------------------------------------------------------

Example Scenario

Requirement: Show related records (e.g., Tasks) for multiple parent tables like Incident, Problem, and Change.

Standard Approach

  • Create a relationship for Incident → Task.
  • Create another for Problem → Task.
  • Create another for Change → Task.

Each relationship is defined separately, even if the query logic is similar.

Scripted Relationship Approach

You can define one scripted relationship that dynamically checks the parent table and returns related tasks:

 

(function executeRelationship(current) { 
var gr = new GlideRecord('task'); 
gr.addQuery('parent', current.sys_id);
gr.query();
 })(current);

This script can be reused, but you still need to configure it for each table where you want the related list to appear.

 

References:

 

 

-------------------------------------------------------------------------------------------------------------------------------------------------

If my response helped, please mark it as the accepted solution so others can benefit as well.

Regards,

Divesh Tyagi