Community Tip - When posting, your subject should be specific and summarize your question. Here are some additional tips on asking a great question. X
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.
Solved! Go to Solution.
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.
You can do an additional Query on the infotable using the InfoTable functions
Here are all the queries that you can use.
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.