How to query data from reference column from a table

t_h1
Giga Contributor

I'm querying alm_asset table using API, there are some reference field that show the API link to that particular referenced table. Is there an easier way to construct the initial URL to also gather the field I want from the referenced table? Or do I have to re-query that referenced table to get the information I need? 

 

For example. alm_asset table has reference field of model_category that links to cmdb_model_category. Currently, I need the cmdb_model_category.name to gather the name of the model_category. So what I'm doing is...

1. Query the alm_asset table, rest returns json with {'model_category: {'link': 'https://company.service-now.com/api/now/table/cmdb_model_category/1a84fd9sf4dsfaf94ds984fd9s', 'value': '1a84fd9sf4dsfaf94ds984fd9s'}}

2. So in my code, I'm re-querying that model_category link to look for the 'name' field. 

This is taking very long time because for each alm_asset row, I'm re-querying reference table three times to gather all the information I need for this API call. 

1 ACCEPTED SOLUTION

MrMuhammad
Giga Sage

HI,

You can try dot walking to achieve this without the need to re-queriyng the referenced tables.

A nice blog on this topic - https://developer.servicenow.com/blog.do?p=/post/dot-walking-in-the-rest-table-api-2/#:~:text=Dot%2D...

Please mark this helpful/correct, if applicable.

Regards,

Muhammad

Regards,
Muhammad

View solution in original post

3 REPLIES 3

MrMuhammad
Giga Sage

HI,

You can try dot walking to achieve this without the need to re-queriyng the referenced tables.

A nice blog on this topic - https://developer.servicenow.com/blog.do?p=/post/dot-walking-in-the-rest-table-api-2/#:~:text=Dot%2D...

Please mark this helpful/correct, if applicable.

Regards,

Muhammad

Regards,
Muhammad

t_h1
Giga Contributor

Thanks that worked. 

Angie Lee
ServiceNow Employee
ServiceNow Employee

Hi t_h,

You can set the parameters of your API to send the display value of the reference field. On the REST API Explorer under query parameters look for sysparm_display_value.