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

Community Tip - When posting, your subject should be specific and summarize your question. Here are some additional tips on asking a great question. X

Can't get ThingTemplate.QueryImplementingThingsWithData(...) to work with Query filter

rtaylor-3
1-Newbie

Can't get ThingTemplate.QueryImplementingThingsWithData(...) to work with Query filter

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":[

  1. {},
    • "fieldName":"property1",
    • "type":"EQ",
    • "value":"1"
  2. {}
    • "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?

1 ACCEPTED SOLUTION

Accepted Solutions
qn
1-Newbie
1-Newbie
(To:rtaylor-3)

You need another "filters" outside:

{

     filters:

     {

          "filters":

          [

               {"fieldName":"property1","type":"EQ","value":"1"},

               {"fieldName":"property2","type":"EQ","value":"1"}

          ],

          "type":"AND"

     }

};

View solution in original post

7 REPLIES 7
qn
1-Newbie
1-Newbie
(To:rtaylor-3)

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

rtaylor-3
1-Newbie
(To:qn)

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.

qn
1-Newbie
1-Newbie
(To:rtaylor-3)

Could you try "type":"And" instead of "type":"AND"​, just in case of syntax.

rtaylor-3
1-Newbie
(To:qn)

No go....still ignoring the filter and pulling back all records.

qn
1-Newbie
1-Newbie
(To:rtaylor-3)

You need another "filters" outside:

{

     filters:

     {

          "filters":

          [

               {"fieldName":"property1","type":"EQ","value":"1"},

               {"fieldName":"property2","type":"EQ","value":"1"}

          ],

          "type":"AND"

     }

};

rtaylor-3
1-Newbie
(To:qn)

Boom! That did it. I should have seen that....just glossed over it. Another set of eyes is always good. Thanks so much!

qn
1-Newbie
1-Newbie
(To:rtaylor-3)

You're welcome!

Top Tags