Composer 中的 ThingWorx 模型定义 > 建模 > 事物 > 警报 > 从警报检索阈值信息
从警报检索阈值信息
限值、最大值、最小值等值存储在 GetAlertDefinition 服务返回的 alertAttributes 信息表中。
要访问信息表内的特定值,需要使用包装器服务。
示例
INTEGER 属性的 Above 警报类型检索限值的服务:
输入
输出
propertyName : STRING
result: INTEGER
* 
结果类型必须与返回的属性类型相匹配。在本示例中,结果为 INTEGER。
alertName : STRING
脚本示例
// These parameters have been parameterized into "alertName" and
// "propertyName" parameters at the service level. If these values
// will not change, they can be hard coded instead.
var params = {
alertName: alertName /* STRING */,
property: propertyName /* STRING */
};
// Retrieve the Alert Definition
var alertDef = me.GetAlertDefinition(params)
// Safety check on result from GetAlertDefinition()
if (alertDef != null && alertDef.rows.length > 0) {
// There should only be one row returned by GetAlertDefinition()
var alertProps = alertDef.rows[0];
// Safety check on alertAttributes infotable.
if (alertProps.alertAttributes != null && alertProps.alertAttributes.rows.length > 0) {
// Return the "limit" property from the alertAttributes table.
var result = alertProps.alertAttributes.rows[0].limit;
} else {
// The alertAttributes infotable was undefined or empty. This logs an error, but
// does not change the value returned. (Service returns no value.)
logger.error("AlertAttributes was null/empty!");
}
} else {
// The Alert Definition was empty.
// This is most commonly caused by invalid alertName/propertyName.
logger.error("Result from GetAlertDefinition was null/empty!");
相关链接