Community Tip - You can subscribe to a forum, label or individual post and receive email notifications when someone posts a new topic or reply. Learn more! X
Good day community,
I am making use of In range alerts to change the values associated with my alerts dynamically. Below is my code. It executes successfully. However, the values on my alert do not change. Does anyone know why this is happening?
var params = {
infoTableName: "InfoTable",
dataShapeName: "NumberRangeAlert"/* DATASHAPENAME */
};
var table = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape(params);
table.minimum = Min;
table.minimumInclusive = minInclusive;
table.maximum = max;
table.maximumInclusive = maxInclusive;
table.calculationValue = 1;
table.calculationType = "Percentage";
table.calculationShow=true;
table.propertyValue=13;
let thingProperties = Things[selectedEntity].GetPropertyDefinitions({
category: 'X' /* STRING */,
type: 'Number' /* BASETYPENAME */,
dataShape: "NumberRangeAlert"/* DATASHAPENAME */
});
for(let i =0; i<thingProperties.length; i++){
let name = thingProperties[i].name;
let alertName = "MyAlert1";
var params1 = {
alertType: "InRange" /* STRING */,
alertName: alertName /* STRING */,
property:name /* STRING */,
description: "InRange" /* STRING */,
attributes: table /* INFOTABLE */,
persistent: true /* BOOLEAN */,
priority: 1 /* INTEGER */,
enabled: true /* BOOLEAN */
};
me.AddOrUpdateAlert(params1);
}
Best Regards,
Solved! Go to Solution.
Quick look through the code, the last line me.AddOrUpdateAlert(params1);, should this be Things[selectedEntity].AddOrUpdateAlert(params1);
Assumptions this service is being called from a helper thing and attempting to modify another things alerts.
Thanks,
Travis
Quick look through the code, the last line me.AddOrUpdateAlert(params1);, should this be Things[selectedEntity].AddOrUpdateAlert(params1);
Assumptions this service is being called from a helper thing and attempting to modify another things alerts.
Thanks,
Travis
thanks travis, This did help.
Below is the code:
var table = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape({
infoTableName : "InfoTable",
dataShapeName : "myDatashape" // This depends on the property used to trigger the alert
});
// result: INFOTABLE dataShape: "PropertyDefinition"
let thingProperties = Things[selectedEntity].GetPropertyDefinitions({
category: 'Cars' /* STRING */,
type: 'String' /* BASETYPENAME */,
dataShape: undefined /* DATASHAPENAME */
});
try{
let myVar1 = Things[selectedEntity].prop;
let Limit1 = normalPhaseVoltage + normalPhaseVoltage*limit/100;
table.limit2 = maxLimit;
table.limitInclusive = limitInclusive;
for(let i =3; i<thingProperties.length; i++){
let propertyName = thingProperties[i].name;
let alertName = propertyName +'_High';
Things[selectedEntity].AddOrUpdateAlert({
alertType: "Above" /* STRING */,
alertName: alertName /* STRING */,
property: propertyName /* STRING */,
description: "Above" /* STRING */,
attributes: table /* INFOTABLE */,
persistent: true /* BOOLEAN */,
priority: 1 /* INTEGER */,
enabled: true /* BOOLEAN */
});
}
Things[selectedEntity].graphDisplay = Limit1;
}catch(err){
}
result = thingProperties;
Regards,