ODBC guide

Read incidents using reference fields


Demonstrates how to query the incident table using reference (foreign key) fields in ServiceNow.

ServiceNow allows filtering on fields from related tables using dot-walking syntax (reference_field.some_field), without requiring explicit joins.

Use these patterns to filter incidents by Caller, Assigned User, Assignment Group, Configuration Item, or other referenced records.

-- 1. Query incidents by caller's username (caller_id → sys_user)
SELECT *
FROM get_table_rows
WITH(
	TableName='incident',
	Query='caller_id.user_name=john.doe'
) 

-- 2. Query incidents by assigned user's display name (assigned_to → sys_user)
SELECT *
FROM get_table_rows
WITH(
	TableName='incident',
	Query='assigned_to.name=Jane Smith'
) 

-- 3. Query incidents by assignment group name (assignment_group → sys_user_group)
SELECT *
FROM get_table_rows
WITH(
	TableName='incident',
	Query='assignment_group.name=Network'
) 

-- 4. Query incidents by configuration item name (cmdb_ci → CMDB record)
SELECT *
FROM get_table_rows
WITH(
	TableName='incident',
	Query='cmdb_ci.name=SRV-APP-01'
) 

-- 5. Combine reference field and local field filters
--    (Network group + High priority incidents)
SELECT *
FROM get_table_rows
WITH(
	TableName='incident',
	Query='assignment_group.name=Network^priority=1'
)