Community Tip - Your Friends List is a way to easily have access to the community members that you interact with the most! X
Hi,
How can I Filter the Things based on Property value ?
Thanks,
Shashi.
Solved! Go to Solution.
or using the QueryImplementingThings / QueryImplementingThingsWithData / QueryImplementingThingsOptimized services like:
var query = {
"filters": {
"type": "And",
"filters": [{
"type": "EQ",
"fieldName": "TheProperty",
"value": "TheValue"
}, {
"type": "EQ",
"fieldName": "TheProperty2",
"value": "TheValue2"
}]
}
};
ThingTemplates["GenericThing"].QueryImplementingThingsWithData({
maxItems: Number.MAX_SAFE_INTEGER/* NUMBER */ ,
tags: undefined /* TAGS */ ,
nameMask: undefined /* STRING */ ,
query: query/* QUERY */
});
- docs for Optimized service https://support.ptc.com/help/thingworx/platform/r9/en/index.html#page/ThingWorx/Help/Best_Practices_for_Developing_Applications/UsingTheQueryImplementingThingsOptimizedService.html
Need to watch out as the query most likely can only include properties the ThingTemplate you reference uses.
All the things inherited from same thing template or thing shape?
If yes, Use getimplemented things with data service and do the query
ThingTemplates["<thingtemplate>"].GetImplementingThingsWithData();
ThingShapes["<thingshape>"].GetImplementingThingsWithData();
If no, create a list of things and get property values by iterating and do the query
Hope it helps
Hi Shashi_Preetham,
Adding to Sathishkumar_C, you can refer to below help center when writing query service for filtering your infotable with Things.
You can try this out, but note that you can only pick 1 thing template here if more than one it won't display the correct result. You can write GenericThing and the result actually will query all of the Things which are rooted to GenericThing. So this one is still working properly and the performance is also good.
Hope this helps you!
Thanks
var query = {
"filters": {
"type": "And",
"filters": [{
"type": "EQ",
"fieldName": "TheProperty",
"value": "TheValue"
}, {
"type": "EQ",
"fieldName": "TheProperty2",
"value": "TheValue2"
}]
}
};
var params = {
maxItems: 500 /* NUMBER */ ,
searchExpression: undefined /* STRING */ ,
types: { "items": ["Thing"] } /* JSON */ ,
thingTemplates: { "items": ["GenericThing"]} /* JSON */ ,
identifierSearchExpression: undefined /* STRING */ ,
modelTags: undefined /* TAGS */ ,
thingShapes: undefined /* JSON */ ,
query: query /* QUERY */ ,
aspects: undefined /* JSON */ ,
excludedAspects: undefined /* JSON */ ,
networks: undefined /* JSON */ ,
maxSearchItems: undefined /* NUMBER */
};
// result: INFOTABLE dataShape: SearchResults
var result = Resources["SearchFunctions"].SearchThings(params);
or using the QueryImplementingThings / QueryImplementingThingsWithData / QueryImplementingThingsOptimized services like:
var query = {
"filters": {
"type": "And",
"filters": [{
"type": "EQ",
"fieldName": "TheProperty",
"value": "TheValue"
}, {
"type": "EQ",
"fieldName": "TheProperty2",
"value": "TheValue2"
}]
}
};
ThingTemplates["GenericThing"].QueryImplementingThingsWithData({
maxItems: Number.MAX_SAFE_INTEGER/* NUMBER */ ,
tags: undefined /* TAGS */ ,
nameMask: undefined /* STRING */ ,
query: query/* QUERY */
});
- docs for Optimized service https://support.ptc.com/help/thingworx/platform/r9/en/index.html#page/ThingWorx/Help/Best_Practices_for_Developing_Applications/UsingTheQueryImplementingThingsOptimizedService.html
Need to watch out as the query most likely can only include properties the ThingTemplate you reference uses.