Community Tip - When posting, your subject should be specific and summarize your question. Here are some additional tips on asking a great question. X
Greetings,
I'm trying to query for implementing things on a template which have certain property values.
I'm doing this in Java.
Here is an example:
ThingTemplate template = // get thing template
String property1Value = "someValue";
String property2Value = "anotherValue";
JSONArray a = new JSONArray();
a.push(newFilterJSONObject("EQ", "property1", property1Value));
a.push(newFilterJSONObject("EQ", "property2", property2Value));
JSONObject filters = new JSONObject();
filters.put("type", "AND");
filters.put("filters", a);
InfoTable results = template.QueryImplementingThingsWithData(500.00, null, null, filters);
This will return all implementing things as if it is ignoring the filter.
I've reviewed the Query docs and am using the composite query example:
var query = {
filters: {
type: "And",
filters: [{
type: "GT",
fieldName: "Duration",
value: "12"
},{
type: "TaggedWith",
fieldName: "tags",
tags: "MaintenanceIssues:PowerOutage"
} ]
}};
This is the resulting JSON from the Java JSONObject above:
{
"filters":[
- {},
- "fieldName":"property1",
- "type":"EQ",
- "value":"1"
- {}
- "fieldName":"property2",
- "type":"EQ",
- "value":"1"
],
"type":"AND"
}
There are no matches in my data so i should be getting back an empty InfoTable, but i'm not.
What am i doing wrong?
Solved! Go to Solution.
You need another "filters" outside:
{
filters:
{
"filters":
[
{"fieldName":"property1","type":"EQ","value":"1"},
{"fieldName":"property2","type":"EQ","value":"1"}
],
"type":"AND"
}
};
The resulting JSON is not "normal", the 2 filters are outside of the {}. Or is it just a problem of copy-paste ?
Have a look on this discussion How to populate query when testing the QueryStreamEntriesWithData service?.
a badly formatted query is ignored and you get all the results
Sorry....copy-n-paste error, below is the generated output:
{
"filters":[
{"fieldName":"property1","type":"EQ","value":"1"},
{"fieldName":"property2","type":"EQ","value":"1"}
],
"type":"AND"
}
And it did review that discussion before posting.
Could you try "type":"And" instead of "type":"AND", just in case of syntax.
No go....still ignoring the filter and pulling back all records.
You need another "filters" outside:
{
filters:
{
"filters":
[
{"fieldName":"property1","type":"EQ","value":"1"},
{"fieldName":"property2","type":"EQ","value":"1"}
],
"type":"AND"
}
};
Boom! That did it. I should have seen that....just glossed over it. Another set of eyes is always good. Thanks so much!
You're welcome!