Community Tip - You can change your system assigned username to something more personal in your community settings. X
Hello,
I'm workin on an app with Thingworx 9.1, user are able to create alert from the app. Know I'm trying to make them able to delete an alert. For this I'm using the RemoveAlert() function, to work it need alertName, property, persistent. I can get all this information from GetAlertDefinitions() service except for the property. And i didn't figure out how to get it. I can find it in the composer but I would like to make it work without the need of using the composer.
Any idea ? Thanks
Solved! Go to Solution.
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:
//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)
Hi @BenjaminD.
Since you're allowing users to create alerts, are you giving them the ability to see what they've created? The reason we're asking is because we don't have a single service that does this, but you could use multiple services for achieving your task. You would also need to be concerned about a user deleting the wrong alert, especially if they didn't create them and therefore may not know whether the alert should be removed. In your use case, should a user have the ability to delete an alert they didn't create?
For identifying the property, you may want to store the alert with the property at the time the alert was created. Then allow the user to do a lookup against that table that contains the alert along with the property.
If we're not understanding, please provide more details around your use case.
Regards.
--Sharon
To answer you question yes user can see the alert they've created and also those created by other and delete both of them. I understand you're solution, but the information is saved natively in thingworx isn't it ? I'd like to get to this information instead of creating a new infotable. Can you tell me about wich service are you thinking in this phrase "you could use multiple services for achieving your task" ?
Thanks for your time and help
Dear @slangley , the solution you propose is not a clean one.
You are proposing we use a custom table to store the link between the alert and the property.
BUT
This link is supposed to already exist out of the box because Thingworx creates an alert on a property.
The question is "How do you get the "out of the box link" between a specific alert definition and the property it's attached to?"
Thanks in advance for your help.
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:
//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)