Skip to main content
nmutterAnswer
Sep 20, 2022 7:32 PM UTC

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.

4 replies

Sep 19, 2022 5:04 AM UTC

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

Sep 20, 2022 10:08 AM UTC

Hi Shashi_Preetham,

 

Adding to Sathishkumar_C, you can refer to below help center when writing query service for filtering your infotable with Things.

https://support.ptc.com/help/thingworx/platform/r9/en/#page/ThingWorx/Help/Composer/Things/ThingServices/QueryParameterforQueryServices.html

 

Sep 20, 2022 12:41 PM UTC

Hi @pshashipreetham 

 

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);

 

nmutterAnswer
Sep 20, 2022 7:32 PM UTC

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.