cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Help us improve the PTC Community by taking this short Community Survey! X

how to log alarms

IA_10816220
10-Marble

how to log alarms

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,

IA_10816220_1-1731213081820.png

 

ACCEPTED SOLUTION

Accepted Solutions

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

View solution in original post

3 REPLIES 3
Velkumar
19-Tanzanite
(To:IA_10816220)

Hi @IA_10816220 

 

QueryAlertHistory service returns history of alerts triggered.

 

Velkumar_0-1731304571272.png

 

/VR

 

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

Announcements


Top Tags