The CreatorCon Call for Content is officially open! Get started here.

CSA exam

Sofvrg
Tera Contributor

What is a reference field in ServiceNow, and how is it used to create relationships between different tables?

1 ACCEPTED SOLUTION

Anand Kumar P
Giga Patron

Hi @Sofvrg ,

 

A reference field is a field type in ServiceNow that links a record from one table to a record in another table, creating a relationship between the two. It stores the sys_id of the referenced record and allows you to access related information through dot-walking.

 

1. Creates Relationships: Links tables, enabling one table to reference data from another.

2. Stores Sys_ID: Stores a unique identifier of the referenced record.

3. Allows Dot-Walking: Access fields of the referenced table directly.

4. Common Use: Simplifies data relationships and avoids duplication.

 

Example: Incident’s caller_id Field

The caller_id field in the Incident table is a reference to the sys_user table.

It lets you select a user as the caller for an incident.

 

Accessing Referenced Fields:

current.caller_id.name: Retrieves the name of the caller.

current.caller_id.email: Retrieves the email of the caller.

 

Simple Example:

 

(function executeRule(current, previous /*null when async*/) {

    // Get the caller's name and email

    var callerName = current.caller_id.name;

    var callerEmail = current.caller_id.email;

    gs.log('Caller Name: ' + callerName);

    gs.log('Caller Email: ' + callerEmail);

})(current, previous);

 

This script retrieves and logs the name and email of the caller from the sys_user table

 

Mark it as helpful and solution proposed if it serves your purpose.
Thanks,
Anand

View solution in original post

4 REPLIES 4

Runjay Patel
Giga Sage

Hi @Sofvrg ,

A reference field in ServiceNow is a powerful tool for creating relationships between tables by storing a reference to a record in another table. This enables the linking of data in a structured and efficient way, allowing users to easily associate records across tables and retrieve related information. Reference fields are essential for data integrity, relationship modeling, and automating workflows in ServiceNow.

Accept and like the solution if it helped.

Abhishek_Thakur
Mega Sage

Hello @Sofvrg ,

Reference field is the field which refer to another table to get the records or values from that table. Like CI & Caller Id in the incident table. Both refer to the different table. CI field refers to the cmdb_ci table whereas caller Id field refers to the sys_user table.

 

You can follow the below to get some more details on it.

https://youtu.be/mG1fXK3HfVs?si=SBNh3743AIiycFHx

 

Please mark my answer as accepted solution and give thumbs up, if it helps you.

Reference fields are a type of field in ServiceNow that link records together. This helps create relationships between different data sets in your ServiceNow instance. They allow you to associate a record on one table with another record on a different table ...

Ravi Chandra_K
Kilo Patron
Kilo Patron

Hello @Sofvrg 

 

Reference field is a field which references the Table.

 

Reference fields are similar to choice fields, but instead of offering a static set of local options, the values are referenced from other Table.

 

Example: Caller field on Incident. (Which holds the Caller value from Sys_user table)

 

 

 

Refer:

 

https://www.servicenow.com/docs/bundle/xanadu-platform-administration/page/administer/field-administ...

 

Please mark the answer as helpful and correct if helped.

 

Kind regards,

Ravi Chandra 

Anand Kumar P
Giga Patron

Hi @Sofvrg ,

 

A reference field is a field type in ServiceNow that links a record from one table to a record in another table, creating a relationship between the two. It stores the sys_id of the referenced record and allows you to access related information through dot-walking.

 

1. Creates Relationships: Links tables, enabling one table to reference data from another.

2. Stores Sys_ID: Stores a unique identifier of the referenced record.

3. Allows Dot-Walking: Access fields of the referenced table directly.

4. Common Use: Simplifies data relationships and avoids duplication.

 

Example: Incident’s caller_id Field

The caller_id field in the Incident table is a reference to the sys_user table.

It lets you select a user as the caller for an incident.

 

Accessing Referenced Fields:

current.caller_id.name: Retrieves the name of the caller.

current.caller_id.email: Retrieves the email of the caller.

 

Simple Example:

 

(function executeRule(current, previous /*null when async*/) {

    // Get the caller's name and email

    var callerName = current.caller_id.name;

    var callerEmail = current.caller_id.email;

    gs.log('Caller Name: ' + callerName);

    gs.log('Caller Email: ' + callerEmail);

})(current, previous);

 

This script retrieves and logs the name and email of the caller from the sys_user table

 

Mark it as helpful and solution proposed if it serves your purpose.
Thanks,
Anand