How to get referencing table of given table using REST API?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2023 03:27 AM
Hi
I have a case in which I need to pull the children tables (referencing tables) of a given table using an API. ServiceNow has this mechanism in UI (screenshot attached), I need similar thing through APIs.
Appreciate your help!!
- Labels:
-
Architect
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2023 11:35 AM
You could use the Table API to query the Dictionary Entries table for all reference and list fields referencing the given table. For example, here's a Table API endpoint to get all tables with foreign key fields referencing Incident:
https://<instance>.service-now.com/api/now/table/sys_dictionary?sysparm_query=internal_type%3Dreference%5EORinternal_type%3Dglide_list%5Ereference%3Dincident&sysparm_fields=name%2Celement
Breaking this down, /api/now/table means we want to use the Table API, /sys_dictionary tells it which table we want to query, the ? signals that we're starting the pairs of GET parameters, which will each be a key and value joined by an = and separated by an &.
The GET parameters are:
- sysparm_query=internal_type=reference^ORinternal_type=glide_list^reference=incident — this encoded query is filtering the results to reference or list fields that point to the incident table
- sysparm_fields=name,element — this tells the system which fields to give us in the result set; you could add more fields if you need more information, or, if the name field is really all you need you could drop the element field
Hope this gets you close to what you need. Cheers!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2023 11:11 PM
@Joey Day, Thanks for your answer.
I have tried this but it doesn’t cover the case I need. For example, the column service_offering is in the Task table which refers to the service_offering table. And since tables like incident, problem extends the Task table, those also refer to the service_offering table. So when I query for the referencing tables of service_offering, the result should also contain incident and problem.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2023 09:32 AM
Hi @vamshi14 , did you find a solution? I have the same problem.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2023 11:44 AM
Hi,
GlideTableHierachy API might be what you are looking for.
https://developer.servicenow.com/dev.do#!/reference/api/tokyo/server/c_GlideTableHierarchyScopedAPI
BR, Jan