Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X
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.
Solved! Go to Solution.
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)
Have you tried adding a RestartThing() after you updated the Alert?
No its not working. Is there any other way I can change the "Limit" of an alert from a service?
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.
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!!!
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)
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?
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."
I guess its working now. Thanks a lot.