Records with Multiple Sys IDs and Display Value effect
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2024 01:44 AM - edited 03-14-2024 02:04 AM
Primary key in database table
We have read that a SYS ID(sys_id) in Servicenow is 32-character GUID (Globally Unique ID) that uniquely identifies each record in an instance. SYS ID is the primary key for a table record in relational database terminology.
Think of it like a key that can open the lock of your vault.
Now, what if I tell you that, a record can hold more than 1 SYS ID...
Dont believe? Check below
Look at the below record:
table: sn_si_m2m_task_affected_user
Note the SYS ID: 01c59185db387f00db9b9875db9619ec
But the same record can also hold another SYS ID: 7b05d1b2dba4f700db9b9875db9619f4
Does it REALLY mean one record in Servicenow can hold 2 SYS IDs?!! Lets verify through list:
But we see that the record points to the SYS ID - 01c59185db387f00db9b9875db9619ec (if we hover the record info bubble icon/ or open the record and check the SYS ID)
No records if searched with the SYS ID7b05d1b2dba4f700db9b9875db9619f4.
Now, we know that the correct SYS ID is 01c59185db387f00db9b9875db9619ec, then how does the other SYS ID 7b05d1b2dba4f700db9b9875db9619f4 opens the same record form? In other words, what exactly this SYS ID is and what is special about this SYS ID?
ANSWER:
The SYS ID 7b05d1b2dba4f700db9b9875db9619f4 comes from the user reference record on the Task Affected User(sn_si_m2m_task_affected_user) record.
And, the special part about this reference field is that it is also acting as a display field for the Task Affected User(sn_si_m2m_task_affected_user) record.
Summary:
If a field is used as display field for any table in Servicenow, it can accept SYS ID to query and open the form for that record. From database point of view, the Entity Integrity Constraint is not violated and the record has ONLY 1 SYS ID as its primary key which is unique.
(While this is applicable for other data type(reference/ non-reference) display field, this might surprisingly appear deceiving at the first look, as we are trained to assume that sys_id url param only accepts its own GUID).
PS: Below are some other places where we could encounter similar behavior.
1. Flow Designer Executions: We can observe this behavior in flow designer executions when querying records and using for Each iterator.
Note: The iterator displays the SYS ID of the record from the display reference field during runtime and not the SYS ID of the actual record.(technically the record is same)
2. Few tables can be opened with their name on the SYS ID parameter
3. Child records of a table could be opened with its SYS ID applied on its parent table. For example: we can open as well as perform query on task table with the incident SYS ID. (however, in this way, we may not access the specific fields of the incident table which are not on task table due to inheritance)
var incGr = new GlideRecord("task");
incGr.get("a83820b58f723300e7e16c7827bdeed2");
gs.print(incGr.number);
*** Script: INC0008111
4. Open any record form where the name field is the display field. For example: User group(sys_user_group) record can be opened with name in SYS ID param.
- 798 Views