Hello,
There is a service GetAlertStatuses on things, it retrieves all alert names with attached property name.

It provides the required information to perform a call to the RemoveAlert service :
me.RemoveAlert({
alertName: "alert1" /* STRING */,
property: "property1" /* STRING */,
persistent: true /* BOOLEAN {"defaultValue":false} */
});
//the persistance of this alert deletion (if thing is saved, platform restarted… be carreful with composer override)
There are other options if you want more information about the alerts:
Here is one way to do it:
- Duplicate the datashape AlertDefinition,
- name the new one : AlertDefinitionWithSourceProperty.
- Add field : "sourceProperty"
- Save
- The code bellow do the following :
- Create the list of all properties of a thing
- For each property, get the list of all alerts with their definitions
- Create as a result the list of all alerts with definition and name of the source property
//Input : thingName
//Output : infotable (AlertDefinitionWithSourceProperty)
let result = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape({
infoTableName: "InfoTable",
dataShapeName: "AlertDefinitionWithSourceProperty"
});
// result: INFOTABLE dataShape: "PropertyDefinition"
let allProperties = Things[thingName].GetPropertyDefinitions({
category: undefined /* STRING */,
type: undefined /* BASETYPENAME */,
dataShape: undefined /* DATASHAPENAME */
});
let i;
let j;
for(i=0;i<allProperties.getRowCount();i++){
let AlertDefinitions = Things[thingName].GetAlertDefinitions({
property: allProperties[i].name
});
for(j=0;j<AlertDefinitions.getRowCount();j++){
// AlertDefinition entry object
let alertEntryOnCurrentProperty ={//AlertDefinitionWithSourceProperty
alertAttributes: AlertDefinitions[j].alertAttributes, // INFOTABLE
alertType: AlertDefinitions[j].alertType, // STRING
name: AlertDefinitions[j].name, // STRING [Primary Key]
description: AlertDefinitions[j].description, // STRING
priority: AlertDefinitions[j].priority, // INTEGER
enabled: AlertDefinitions[j].enabled, // BOOLEAN
sourceProperty: allProperties[i].name
};
result.AddRow(alertEntryOnCurrentProperty);
}
}
//Then you can use the columns "name" and "source property" (of a selected row in a mashup ?) to perform the alert deletion.
"user can see the alert they've created and also those created by other and delete both of them"
as Sharon suggests, be careful if you also also have alerts created by administrators, that should not be removed at all (as the one manageable by any user with permissions). Her solution with additional persisted infotable works for this case too. (with second solution, you can also use property categories to mark and filter the properties)