ThingWorx Model Definition in Composer > Modeling > Code Snippets > QueryImplementingThingsOptimizedWithTotalCount
QueryImplementingThingsOptimizedWithTotalCount
Description
You can use this service to query the Things that implement the Thing Template or Thing Shape on which the service is run. The result is an infotable that contains the Things that implement the template or Data Shape and the property values of the Thing Template or Thing Shape on which the query is run.
Input
Parameter Name
Description
Base Type
maxItems
Maximum number of items to return in the result set. The default value is 500. This parameter is applied after all other filters are applied.
NUMBER
tags
The model tags associated with the source of this entry.
TAGS
nameMask
The name pattern for the entities that implement the Thing Template or Thing Shape.
STRING
query
The query criteria used to filter the data.
Filters can only be written for the effective properties of the Thing Template or Thing Shape on which the service is run.
For more information, see Query Parameter for Query Services.
QUERY
withPermissions
If true, permission information is included in the result.
BOOLEAN
basicPropertyNames
An infotable that contains a list of basic properties, such as isSystemObject, name, description, homeMashup, avatar, and tags.
The expected Data Shape for the infotable is EntityList.
INFOTABLE
propertyNames
An infotable that contains a list of specific properties of the Thing Template or Thing Shape. The specified properties must be defined on the Thing Template or Thing Shape on which the service is run.
The expected Data Shape for the infotable is EntityList.
INFOTABLE
networkName
The network name on which to filter. The query will only return results from Things in that network.
networkParentNode
Name of the top node in the network that is specified in networkName. The query will return all children from the specified parent node in the network.
STRING
networkMaxDepth
Maximum depth to search in the network. The query returns the full hierarchy of children if this value is set to 0, which is the default.
INTEGER
offset
The number of rows to skip before starting to return rows from the query. If set to the default value of 0, the query will return all rows. This can be used for paginating the results.
NUMBER
Output
Parameter Name
Description
Base Type
result
Returns an infotable that contains the list of Things that implement the Thing Template or Thing Shape and the requested properties of the Thing Template or Thing Shape and their values. The Data Shape for the infotable is ImplementedThingsWithTotalCount.
INFOTABLE
Example
Entity
ShapeProp1
ShapeProp2
ShapeProp3
ThingShape1
Defined
NA
NA
ThingShape2
NA
Defined
NA
ThingShape2
NA
NA
Defined
Entity
Parent Thing Template
Prop1
Prop2
Prop3
Prop4
Implemented Thing Shape
Effective Properties
Template1
Defined
NA
NA
NA
ThingShape1
Prop1, ShapeProp1
Template2
Template1
Inherited from Template1
Defined
NA
NA
ThingShape2
Prop1,
Prop2,
ShapeProp1,
ShapeProp2
Template3
Template2
Inherited from Template2
Inherited from Template2
Defined
NA
Prop1,
Prop2,
Prop3,
ShapePropy1,
ShapeProp2
Template4
Template2
Inherited from Template2
Inherited from Template2
NA
Defined
ThingShape4
Prop1,
Prop2,
Prop4,
ShapeProp1,
ShapeProp2,
ShapeProp4
Entity
Implements
Model Tags
Prop1
Prop2
Prop3
Prop4
Thing1
Template1
{vocabulary: "MT1", vocabularyTerm: "MT1-MTerm1"}
Val1-1
Thing2
Template2
{vocabulary: "MT1", vocabularyTerm: "MT1-MTerm1"}
Val2-1
Val2-2
Thing3
Template3
{vocabulary: "MT1", vocabularyTerm: "MT1-MTerm1"}
Val3-1
Val3-2
Val3-3
Thing4
Template4
{vocabulary: "MT1", vocabularyTerm: "MT1-MTerm2"}
Val4-1
Val4-2
Val4-4
In the following query, the resulting infotable contains the requested basic properties (name, description, tags, homeMashup), the requested properties on the Thing Template (Prop1), and the name of the Thing.
The following code will query for implementing Things with data using all supported parameters.
var params = {
infoTableName : "InfoTable",
dataShapeName : "EntityList"
};
// CreateInfoTableFromDataShape
var basicpropInfoTable = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape(params);

// EntityList entry object
var basicProp1 = new Object();
basicProp1.name = "name";
basicProp1.description = undefined;

var basicProp2 = new Object();
basicProp2.name = "description";
basicProp2.description = undefined;

var basicProp3 = new Object();
basicProp3.name = "tags";
basicProp3.description = undefined;

var basicProp4 = new Object();
basicProp4.name = "homeMashup";
basicProp4.description = undefined;

basicpropInfoTable.AddRow(basicProp1);
basicpropInfoTable.AddRow(basicProp2);
basicpropInfoTable.AddRow(basicProp3);
basicpropInfoTable.AddRow(basicProp4);

var propertyNamesInfoTable = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape(params);

var prop1 = new Object();
prop1.name = "Property1";
prop1.description = undefined;

var prop2 = new Object();
prop2.name = "Property4";
prop2.description = undefined;

propertyNamesInfoTable.AddRow(prop1);

result = ThingTemplates["Template1"].QueryImplementingThingsOptimizedWithTotalCount({
maxItems: 50 ,
nameMask: "T*",
tags: "MT1:MT1-MTerm1",
query: "{\"filters\":{\"type\": \"LIKE\", \"fieldName\": \"Property1\", \"value\": \"Val*\" }}",
basicPropertyNames: basicpropInfoTable,
propertyNames: propertyNamesInfoTable,
networkName: 'Network1',
networkParentNode: 'TestThing1',
networkMaxDepth: 0,
offset: 0
});
Was this helpful?