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

Community Tip - You can subscribe to a forum, label or individual post and receive email notifications when someone posts a new topic or reply. Learn more! X

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

biswa
10-Marble

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

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. 

1 ACCEPTED SOLUTION

Accepted Solutions
PaiChung
22-Sapphire I
(To:biswa)

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)

View solution in original post

8 REPLIES 8
PaiChung
22-Sapphire I
(To:biswa)

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

biswa
10-Marble
(To:PaiChung)

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

PaiChung
22-Sapphire I
(To:biswa)

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.

biswa
10-Marble
(To:PaiChung)

Seems like now its working. But I noticed one thing that its not working immediately. I have to logout of the composer and then login again or refresh the composer again to see the change. Is there any way I can avoid this? And also I had another doubt. Actually I am making a digital twin of a oil and gas plant. Does using RestartThing() effect the functioning of any component of the plant!!!

PaiChung
22-Sapphire I
(To:biswa)

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)

biswa
10-Marble
(To:PaiChung)

Thanks for the information.

Just one last thing, the services that I have written for creating an alert works but the problem is it gets reflected only after I logout and login again. Is there any way I can see those created alerts as soon as the service run is completed without logging out and logging in again?

PaiChung
22-Sapphire I
(To:biswa)

This didn't work for you?

"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."

biswa
10-Marble
(To:PaiChung)

I guess its working now. Thanks a lot.

Top Tags