Skip to main content
1-Visitor
October 21, 2016
Question

Setting Alert Overrides Programmatically

  • October 21, 2016
  • 4 replies
  • 6241 views

Hi All

I have created Alerts on properties of ThingShapes and ThingTemplates. I notice that when enabling or disabling these Alerts (programmatically) whether they are disabled on a Thing or the Template/Shape that they are enabled/disabled acroos all Assets.

To get around this I notice that I can change the Alert on individual Things (in the Composer) to be Overriden. So that when enabling/disabling alerts on Things (programmatically) I am able to enable/disable them on only that Thing rather than across them all.

My question is, can I set an Alert to "Override" on a Thing Instance programmatically without having to go into the Composer?

Many Thanks

Ashley

4 replies

5-Regular Member
October 21, 2016

Ashley, have you tried using the 'DisableAlertsForProperty' service? You should be able to disable specific alerts on specific properties for that Thing.

ashleyg1-VisitorAuthor
1-Visitor
October 24, 2016

Hi Aanjan,

Apologies for the late reply.

Yes I assumed that executing this service on a Thing Instance would only disable the Alert for that Thing. However when executing DisableAlertsForProperty() (even on a Thing Instance) still disables that Alert for all Things in the ThingTemplate/ThingShape.

If I go into the Composer and Manage that Alert on the Thing Instance I am able to set an "Override" from the dropdown. When this is set I can then do the functionality I want with DisableAlertsForProperty() on that Instance. However my quesiton is can I set "Override" programmatically instead of having to go into the Composer for each Thing?

Thanks

Ashley

5-Regular Member
October 24, 2016

Ashley, is that a Remote Thing/ Remote property by any chance?

ashleyg1-VisitorAuthor
1-Visitor
October 31, 2016

Bump

1-Visitor
September 1, 2017

Hi,

I have the same issus. It her any news about override alerts from template programmatically?

ashleyg1-VisitorAuthor
1-Visitor
September 1, 2017

Hi David,

PTC have notified me that this bug is fixed in 7.4, I believe I have tested it and this now works.

1-Visitor
September 1, 2017

Ok, I'm not realy sure what bug you mean. I'm searching for a code example to override a alert.

I will get the alert from template:

alert_01.png

to the thing:

alert_02.png

1-Visitor
September 1, 2017

Hi Ashley,

Not sure if you solved this but I run this script on a thing to programmatically enable overrides (I'm using 7.2). It pulls the current alert definitions and reapplies them turning on the override.

var properties = me.GetPropertyDefinitions();

var tableLengthProps = properties.rows.length;

for (var x = 0; x < tableLengthProps; x++) {

var row = properties.rows;

    var paramsAlertDef = {

        property: row.name /* STRING */

    };

    // result: INFOTABLE dataShape: "AlertDefinition"

    var alertDefinitions = me.GetAlertDefinitions(paramsAlertDef);

    var tableLengthAlertDefs = alertDefinitions.rows.length;

    for (var y = 0; y < tableLengthAlertDefs; y++) {

        var rowAlertDefs = alertDefinitions.rows;

        var params = {

            alertType: rowAlertDefs.alertType /* STRING */,

            alertName: rowAlertDefs.name /* STRING */,

            property: row.name /* STRING */,

            description: rowAlertDefs.description /* STRING */,

            attributes: rowAlertDefs.alertAttributes /* INFOTABLE */,

            priority: rowAlertDefs.priority /* INTEGER */,

            persistent: true /* BOOLEAN */,

            enabled: rowAlertDefs.enabled /* BOOLEAN */

        };

       

        me.AddOrUpdateAlert(params);

    }

}

1-Visitor
September 7, 2017

Hi Matt,

nice, thanks this works well for me.