- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2024 12:48 AM
What is a reference field in ServiceNow, and how is it used to create relationships between different tables?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-08-2024 12:07 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2024 09:14 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2024 09:29 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2024 11:14 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-08-2024 12:07 AM
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