cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Need help navigating or using the PTC Community? Contact the community team. X

Filtering the get rest api and returning only the filtered data

svisveswaraiya
17-Peridot

Filtering the get rest api and returning only the filtered data

Hi,

I am using get rest api call and fetching a set of Id and Name. I wanted to pass an argument or filter using the Id field and fetch the data for that respective id alone. How can I acheive this in thingworx javascript? I have mentioned my get service below.

 


var headers = { "Content-Type": "application/json"};

var url = "http://"+ me.host + ":" + me.port + "/api/parametersets";

var params = {
proxyScheme: undefined /* STRING */,
headers: headers /* JSON */,
ignoreSSLErrors: undefined /* BOOLEAN */,
useNTLM: undefined /* BOOLEAN */,
workstation: undefined /* STRING */,
useProxy: undefined /* BOOLEAN */,
withCookies: undefined /* BOOLEAN */,
proxyHost: undefined /* STRING */,
url: url /* STRING */,
timeout: 15 /* NUMBER */,
proxyPort: undefined /* INTEGER */,
password: undefined /* STRING */,
domain: undefined /* STRING */,
username: undefined /* STRING */
};

try {
var json = Resources["ContentLoaderFunctions"].GetJSON(params);

var param1s = {
infoTableName : "InfoTable",
dataShapeName : "FTMParameterSetDS"
};

var newInfo = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape(param1s);
var value = json.array.length;

for(var i=0; i<json.array.length; i++)
{
if (json.array[i].Id != null && json.array[i].Id !== "" && json.array[i].Id !=" ")
{
if (json.array[i].Name != null )
{
newInfo.AddRow({Id:json.array[i].Id,
Name:json.array[i].Name});
}
}
}
result = newInfo;
}
catch(err)
{
me.CloseSession();
}

I have attached my output for this get api in which I want to filter w.r.t Id column.

 

Thanks in advance,

svisveswaraiya.

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

There isn't a way to combine it with Query, but if you look in the InfoTableFunctions you'll find Distinct as a service as well.

View solution in original post

4 REPLIES 4

You can do an additional Query on the infotable using the InfoTable functions

Here are all the queries that you can use.

http://support.ptc.com/help/thingworx_hc/thingworx_8_hc/en/index.html#page/ThingWorx%2FHelp%2FComposer%2FThings%2FThingServices%2FQueryParameterforQueryServices.html

 

Hi @PaiChung,

Thanks for your swift response. I tried using LIKE operation from the link and it worked for me. Is there any query to fetch only distinct values from get rest api call. For eg: I want to fetch only distinct column 'Name'.

 

There isn't a way to combine it with Query, but if you look in the InfoTableFunctions you'll find Distinct as a service as well.

Hi @PaiChung,

Yes, I tried the distinct infotable function and it worked for me. Thanks a lot for your help.

 

Thanks,

svisveswaraiya. 

Top Tags