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

Filter Things Based on the Property Value

pshashipreetham
17-Peridot

Filter Things Based on the Property Value

Hi, 

How can I Filter the Things based on Property value ?

Thanks,
Shashi.

Shashi Preetham
1 ACCEPTED SOLUTION

Accepted Solutions
nmutter
14-Alexandrite
(To:danmorin)

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.

View solution in original post

4 REPLIES 4

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.

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

 

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

 

nmutter
14-Alexandrite
(To:danmorin)

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.

Top Tags