Skip to main content
11-Garnet
July 26, 2019
Solved

How to edit/update an alert limits from a Service.

  • July 26, 2019
  • 8 replies
  • 3106 views

Hi All,

 

I want to update the limits of an alert by triggering a service. How can I achieve that?

From Thingworx Support, I got the following code which I have pasted below. I tried running that but it doesnot work.

For example: I have a property "Suction" with basetype as "INTEGER". I have already created an alert for that named "AboveLimit" which will be fired when Suction is above limit 5. Now I want to change the limit through a service. I wrote the following but its not working.

 

// 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 = 10;			 // Alert will trigger when field >=10
row.limitInclusive = true;		// Alert includes 10
attrs.AddRow(row);

// Call the AddOrUpdateAlert Service
var params = {
	alertType: "Above" /* STRING */,
	alertName: "AboveLimit" /* STRING */,
	property: "Suction" /* STRING */,
	attributes: attrs /* INFOTABLE */,
 	priority: 1 /* INTEGER */,
	persistent: true /* BOOLEAN */,
	enabled: true /* BOOLEAN */
};

me.AddOrUpdateAlert(params);

 Please help to achieve the following!!!

 

Thanks in advance. 

Best answer by PaiChung

Composer you just need to do a Save/Cancel/Edit type action to refresh the Thing, it caches the info and a programmatic change will not force the refresh, Save/Cancel/Edit will force a reload from the entity storage.

 

The RestartThing will do exactly that, which means that non-persistent properties will reset to default, if there is a system action involving that Thing while it is being restarted, it will fail (time to restart should in general be very short millisecond(s)

8 replies

22-Sapphire I
July 26, 2019

Have you tried adding a RestartThing() after you updated the Alert?

biswa11-GarnetAuthor
11-Garnet
July 29, 2019

No its not working. Is there any other way I can change the "Limit" of an alert from a service?

22-Sapphire I
July 29, 2019

If the code is working correctly then the only other way would probably be to first remove the alert and then add your new one.