Skip to main content
16-Pearl
December 12, 2022
Solved

Add or Update alert snippet, is not updating the alert

  • December 12, 2022
  • 1 reply
  • 972 views

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,

Best answer by TravisPickett

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

1 reply

12-Amethyst
December 13, 2022

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

Janicen16-PearlAuthor
16-Pearl
December 19, 2022

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,