cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Need to share some code when posting a question or reply? Make sure to use the "Insert code sample" menu option. Learn more! X

Add or Update alert snippet, is not updating the alert

Tomellache2B
14-Alexandrite

Add or Update alert snippet, is not updating the alert

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,

1 ACCEPTED SOLUTION

Accepted Solutions

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

View solution in original post

2 REPLIES 2

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,

Top Tags