Skip to main content
1-Visitor
April 30, 2019
Solved

Is the alert example code on this page still valid as of 8.4?

  • April 30, 2019
  • 1 reply
  • 4756 views

https://support.ptc.com/cs/help/thingworx_hc/thingworx_7.0_hc/index.jspx?id=thingworx0303&action=show

 

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

Best answer by AnnaAn

Attached the entity file.

1 reply

22-Sapphire I
April 30, 2019

Any more info in the logs in regards to the error?

1-Visitor
April 30, 2019

The logs are about as helpful as you'd expect - "[message: Execution error in service script [AlertAddUpdate] :: Alert Attributes For [Above] are not valid]"

22-Sapphire I
May 2, 2019

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?