Pass Multiple values for same parameter in REST get method

harishdasari
Tera Guru

Hi,

I am trying to fetch some details using REST API GET method.

I am successfully able to retrieve the information.

But here issue I have a table and it contains multiple unique id's.

I need to pass multiple Unique Ids for single parameter, I tried something like below, but it is sending only one uniqueid along with the request. and I am receiving response for only one id

for example:

Here is the JSON format

{

"unique_id" : current.getValue('u_unique_id")

}

Anyone could you please help.

 

6 REPLIES 6

Brad Tilton
ServiceNow Employee
ServiceNow Employee

Where are you sending this from? Are you trying to return multiple records? Could you post at least part of the request and response payloads?

harishdasari
Tera Guru

Hi Brad,

Thanks for the response to my thread.

Below is the code I am using to send the requestBody in JSON format and getting the response from the system.

I have created custom table, it already contain some Unique_ID values. so I have written business rule to fetch details using GET method.

when the table is updated, this business rule will triggered and Unique id is sent in request body which is already available in table.

Problem is only one unique id is getting sending in the request and it is fetching response for only one unique id.

Please help me how can I use all the Unique_id values from the table in this GET request and get response body for all the unique id values.

var dataId = {
					"unique_id" : current.getValue('u_unique_id')
				};
			var Livscore = new sn_ws.RESTMessageV2('Live cricket score', 'GET SCORE');
			Livscore.setRequestHeader('accept', 'application/json');
			Livscore.setRequestHeader('content-type', 'aplication/json');
			Livscore.setRequestHeader('apikey', 'vuDsDrnsdJW3yNLcO1Fl2iJOcjq2');
			Livscore.setRequestBody(JSON.stringify(dataId));
			gs.log('************* executing part 2 in *****');
				
			var response1 = Livscore.execute();
			var responseBody1 = response1.getBody();
				gs.log(responseBody1);
			var httpStatus = response1.getStatusCode();

 

 

So you've created a u_unique_id field on your custom table. Does that field hold multiple values, or are you looking to grab the value of that field from multiple records. If it's the latter you'll need to do a GlideRecord query of the table to query multiple records and get the value of that field from each record.

What is the reason for using the custom u_unique_field? Does that value correspond with a record in an external system? Each table in ServiceNow already has a unique identifier called sys_id that you could use if necessary.

custom table already hold the Unique_id values. like 11181991, 1181919 something like this.

 

the reason why I have created custom u_unique_id field because that has correspond values in it and we use these values to retrieve the response for each unique_id and we will parse the response and store all the required value in another table.

 

How can I send the all unique_id's in the GET request using JSON format and get response for all the unique_id's.

 

Thank you.