Community Tip - Did you get an answer that solved your problem? Please mark it as an Accepted Solution so others with the same problem can find the answer easily. X
Hi,
I do create alerts for properties inside the things like the attached photo, is there a way to log these alerts when it happens into the database, and if yes, how i can query them back, like i want to query something that shows me the alert history for a certain property,
thank you,
Solved! Go to Solution.
To your questions,
1. Alerts are stored automatically,
2. The right way to query alert history is on the Thing which fired the alert. In this case it is somewhat similar to querying value streams -- you do it in the entity context. In your subscription the thing name is in the "source" parameter, so you'd do something like this:
// Parameters depend on the type of alert you need, see Help for details
let allAlerts = Things[source].QueryAlertHistory({
oldestFirst: undefined /* BOOLEAN */,
maxItems: undefined /* NUMBER {"defaultValue":500} */,
endDate: undefined /* DATETIME */,
query: undefined /* QUERY */,
startDate: undefined /* DATETIME */
});
Having said that, there's usually a better solution than querying alerts history in an alert subscription, which can be very inefficient, especially if your alerts fire frequently. We might be able to suggest you something better if you describe your use case in more detail.
/ Constantine
Actually, what i meant is how to store it in database like using value stream or something like that, or it accurse automatically, and if it does, how to do the QueryAlertHistory in script inside a subscriber
thanks,
To your questions,
1. Alerts are stored automatically,
2. The right way to query alert history is on the Thing which fired the alert. In this case it is somewhat similar to querying value streams -- you do it in the entity context. In your subscription the thing name is in the "source" parameter, so you'd do something like this:
// Parameters depend on the type of alert you need, see Help for details
let allAlerts = Things[source].QueryAlertHistory({
oldestFirst: undefined /* BOOLEAN */,
maxItems: undefined /* NUMBER {"defaultValue":500} */,
endDate: undefined /* DATETIME */,
query: undefined /* QUERY */,
startDate: undefined /* DATETIME */
});
Having said that, there's usually a better solution than querying alerts history in an alert subscription, which can be very inefficient, especially if your alerts fire frequently. We might be able to suggest you something better if you describe your use case in more detail.
/ Constantine