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
At the bottom of this page there is an example of how to add or edit an alert for a given property. However when I try and implement this I get the error: "Error executing service AlertAddUpdate. Message :: Alert Attributes For [Above] are not valid - See Script Error Log for more details."
The only attributes we need to set are the limit and the limit inclusive if I'm correct, so why would I be getting this error message? I have changed the property variable name to a property on the thing where I am implementing this service.
// Create the Attributes Infotable for AddOrUpdateAlert call var params = { infoTableName: "alertAttr" /* STRING */ }; var attrs = Resources["InfoTableFunctions"].CreateInfoTable(params); // Define the fields required by an Above type Alert for an INTEGER field (not the values!) // limit - Minimum value at which the alert will trigger. var field = new Object(); field.name = "limit"; field.baseType = 'INTEGER'; attrs.AddField(field); // limitInclusive - Is the condition Greater than (>) or Greater than or equal (>=)? field.name = "limitInclusive"; field.baseType = 'BOOLEAN'; attrs.AddField(field); // Define the new Alert values and add the row to the table. var row = new Object(); row.limit = 5; // Alert will trigger when field >=5 row.limitInclusive = true; // Alert includes 5 attrs.AddRow(row); // Call the AddOrUpdateAlert Service var params = { alertType: "Above" /* STRING */, alertName: "MyAlert" /* STRING */, property: "Sensor_Value2" /* STRING */, attributes: attrs /* INFOTABLE */, priority: 1 /* INTEGER */, persistent: true /* BOOLEAN */, enabled: true /* BOOLEAN */ }; me.AddOrUpdateAlert(params);
This is my code just for reference.
Thanks,
Jon
Solved! Go to Solution.
Any more info in the logs in regards to the error?
The logs are about as helpful as you'd expect - "[message: Execution error in service script [AlertAddUpdate] :: Alert Attributes For [Above] are not valid]"
I guess it is saying that the attributes you specified for Above are wrong. I would pull the attributes from an existing alert to check if either you have it incorrect or if it has changed.
Maybe a spelling issue?
So the code on the website is wrong? Because the attributes are defined all within this service.
I haven't looked at it in depth sorry so I'm not sure, but I do know that for the different type of alerts, the attributes are slightly different. That's why i recommend just pulling one from a configured one so you know exactly what is the right info.
Hi, The code example should work for some Alert Types(Above, Below,etc.), but for some Alert Types like InRange, OutOfRange(I did not verify each each just these two are verified) it will not work. Instead use the ThingWorx build-in DataShape like IntegerRangeAlert to create InfoTable(CreateInfoTableFromDataShape) to hold the Attrbute table. I have created a sample for your reference(two services, one is Above, another is for OutOfRange) please import into your system and try again.
Not sure why it did not work for you for the original code for Above Alert Type, it worked for me.
Thank you, works fine for me now.