Sharing related list of records in a table via api

Raunak kapoor2
Tera Expert

I want to share data via API for business application table. I am able to share the records in the table, however it does not share the related list of the records.

 

Is there a way to share the related list of the records in a table?

 

3 REPLIES 3

Karthiga S
Kilo Sage

Hi @Raunak kapoor2 

 

Yes, you can share the related list of records in a table via API in ServiceNow. You can use the ServiceNow Table API to retrieve the related list of records. 

1. Identify the table and the related list you want to share. The related list is usually another table that has a reference field to the original table.

2. Use the ServiceNow Table API to retrieve the records from the original table. The API endpoint is usually in the format of https://.service-now.com/api/now/table/.

3. For each record in the original table, use the sys_id of the record to retrieve the related list. The API endpoint is usually in the format of https://.service-now.com/api/now/table/?sysparm_query==.

4. The response from the API will be a list of records in the related list that are associated with the original record.

 

var instance = 'your_instance';
var table_name = 'your_table';
var related_list_table_name = 'your_related_list_table';
var reference_field = 'your_reference_field';

var request = new sn_ws.RESTMessageV2();
request.setHttpMethod('get');
request.setEndpoint('https://' + instance + '.service-now.com/api/now/table/' + table_name);
request.execute();

var response = request.getResponse();
var records = JSON.parse(response.getBody()).result;

for (var i = 0; i < records.length; i++) {
var sys_id = records[i].sys_id;

request.setEndpoint('https://' + instance + '.service-now.com/api/now/table/' + related_list_table_name + '?sysparm_query=' + reference_field + '=' + sys_id);
request.execute();

var related_list = JSON.parse(request.getResponse().getBody()).result;
// related_list is the related list of the record
}


Please replace 'your_instance', 'your_table', 'your_related_list_table', and 'your_reference_field' with your actual instance name, table name, related list table name, and reference field name.

 

Please mark it Correct and Hit Like if you find this helpful!

 

Regards,

Karthiga

Could you please explain how can i share the related list clearly?

I am using rest api explorer to generate the endpoints, and testing via postman.

where/which option can i use to share the related list ?

Hi - have you received any update on this? I have the same question.  Thanks