QueryNamedPropertyHistory
Description
This service queries the history of logged properties based on the input parameters.
Inputs
Parameter Name
Description
Base Type
propertyNames
An infotable that contains a list of logged properties of the Thing.
The expected Data Shape for the infotable is EntityList.
INFOTABLE
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
startDate
The time stamp after which a value was logged.
DATETIME
endDate
The timestamp before which a value was logged.
DATETIME
quality
The quality of the logged entry for the property. Multiple values can be separated with a pipe (|). The valid options are GOOD, BAD, and UNKNOWN.
STRING
fillOption
Valid options are Previous and None. If Previous is requested, the previous value will be reported when the given property does not have an update while other properties are updated. If None is requested, no value will be reported when the given property does not have an update while other properties are updated.
The default is Previous.
STRING
oldestFirst
Retrieve from the oldest or newest records. The default value is False.
BOOLEAN
query
Additional query criteria to filter data.
For more information, see Query Parameter for Query Services.
QUERY
returnedMetadata
Defines the extra columns that can be requested in additional to Property Name, timestamp and property value.
The default value is Quality.
STRING
Output
Parameter Name
Description
Base Type
result
Returns an infotable that contains the list of historical values of the requested properties.
INFOTABLE
Example
In the following example, Thing1 has the properties Prop1 and Prop2 with values entered in the following order:
Entity
Prop1
Prop2
Thing1
1
2
11
22
In the following query, the resulting infotable will contain timestamp, Prop1, Prop1_Quality, Prop2, and Prop2_quality:
var params = {
infoTableName : "InfoTable",
dataShapeName : "EntityList"
};

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 = "Prop2"; // STRING [Primary Key]
prop2.description = undefined; // STRING

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


// result: INFOTABLE dataShape: ""
let result = Things["Thing1"].QueryNamedPropertyHistory({
propertyNames: propertyNamesInfoTable,
maxItems: 5,
startDate: new Date(new Date().setFullYear(new Date().getFullYear() - 1)),
endDate: Date.now(),
quality: 'GOOD|BAD',
fillOption: 'Previous',
oldestFirst: false,
query: "{ \"sorts\": [{\"fieldName\": \"Prop1\"}]}",
returnedMetadata: 'Quality'

});
In the following query, the resulting infotable will contain timestamp, Prop1, and Prop2:
var params = {
infoTableName : "InfoTable",
dataShapeName : "EntityList"
};

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 = "Prop2"; // STRING [Primary Key]
prop2.description = undefined; // STRING

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


// result: INFOTABLE dataShape: ""
let result = Things["Thing1"].QueryNamedPropertyHistory({
propertyNames: propertyNamesInfoTable,
maxItems: 5,
startDate: new Date(new Date().setFullYear(new Date().getFullYear() - 1)),
endDate: Date.now(),
quality: 'GOOD|BAD',
fillOption: 'None',
oldestFirst: false,
query: "{ \"sorts\": [{\"fieldName\": \"Prop1\"}]}",
returnedMetadata: 'Quality'

});

Was this helpful?