ThingWorx Model Definition in Composer > Modeling > Code Snippets > QueryImplementingThingsWithNamedData
QueryImplementingThingsWithNamedData
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 property names are passed as the input parameters (basicPropertyNames and propertyNames). The result is an infotable that contains the Things that implement the Thing Template or Thing 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 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
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 expected Data Shape for the infotable is EntityList.
INFOTABLE
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.
INFOTABLE
Example
In the following example, TestStream has a Data Shape that has Property1, Property2, and Property3 fields.
Entity
ShapeProp1
ShapeProp2
ShapeProp3
ThingShape1
Defined
NA
NA
ThingShape2
NA
NA
NA
ThingShape2
NA
NA
Defined
Entity
Parent Template
Prop1
Prop2
Prop3
Prop4
Implemented 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
ShapeProp1
ShapeProp2
ShapeProp4
Thing1
Template1
{vocabulary: "MT1", vocabularyTerm: "MT1-MTerm1"}
Val1-1
SVal1-1
Thing2
Template2
{vocabulary: "MT1", vocabularyTerm: "MT1-MTerm1"}
Val2-1
Val2-2
SVal2-1
SVal2-2
Thing3
Template3
{vocabulary: "MT1", vocabularyTerm: "MT1-MTerm1"}
Val3-1
Val3-2
Val3-3
SVal3-1
SVa3l-2
Thing4
Template4
{vocabulary: "MT1", vocabularyTerm: "MT1-MTerm2"}
Val4-1
Val4-2
Val4-4
SVal4-1
SVal3-2
SVal4-4
The following example shows a query for implementing Things with data using its supported parameters. This API call returns an infotable that contains the requested basic properties and other properties from the Thing Template or Thing Shape that match the input parameters.
After running the following query, the resulting infotable will contain name, description, tags, Prop1, and ShapeProp4.
var params = {
infoTableName : "InfoTable",
dataShapeName : "EntityList"
};
// CreateInfoTableFromDataShape
var basicpropInfoTable = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape(params);

// EntityList entry object
var basicProp1 = new Object();
basicProp1.name = "name"; // STRING [Primary Key]
basicProp1.description = undefined; // STRING

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

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

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

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

// EntityList entry object
var prop1 = new Object();
prop1.name = "Prop1"; // STRING [Primary Key]
prop1.description = undefined; // STRING

var prop2 = new Object();
prop2.name = "ShapeProp4"; // STRING [Primary Key]
prop2.description = undefined; // STRING

propertyNamesInfoTable.AddRow(prop1);
propertyNamesInfoTable.AddRow(prop2);

result = ThingTemplates["Template4"].QueryImplementingThingsWithNamedData({
maxItems: 50 /* NUMBER {"defaultValue":500} */,
nameMask: "T*" /* STRING */,
tags: "MT1:MT1-MTerm1",
query: "{\"filters\":{\"type\": \"LIKE\", \"fieldName\": \"Prop1\", \"value\": \"Val*\" }}",
basicPropertyNames: basicpropInfoTable,
propertyNames: propertyNamesInfoTable
});
After running the following query, the resulting infotable will contain name, description, tags, and ShapeProp1.
var params = {
infoTableName : "InfoTable",
dataShapeName : "EntityList"
};
// CreateInfoTableFromDataShape
var basicpropInfoTable = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape(params);

// EntityList entry object
var basicProp1 = new Object();
basicProp1.name = "name"; // STRING [Primary Key]
basicProp1.description = undefined; // STRING

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

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

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

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

// EntityList entry object
var prop1 = new Object();
prop1.name = "ShapeProp1"; // STRING [Primary Key]
prop1.description = undefined; // STRING

propertyNamesInfoTable.AddRow(prop1);

result = ThingShapes["ThingShape1"].QueryImplementingThingsWithNamedData({
maxItems: 50 /* NUMBER {"defaultValue":500} */,
nameMask: "T*" /* STRING */,
tags: "MT1:MT1-MTerm1",
query: "{\"filters\":{\"type\": \"LIKE\", \"fieldName\": \"ShapeProp1\", \"value\": \"S*al*\" }}",
basicPropertyNames: basicpropInfoTable,
propertyNames: propertyNamesInfoTable
});
Was this helpful?