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

Community Tip - Need to share some code when posting a question or reply? Make sure to use the "Insert code sample" menu option. Learn more! X

How to get the last logged entry prior to a given time

khayes1
13-Aquamarine

How to get the last logged entry prior to a given time

Hi,

I have a service that takes an event time stamp as the input. In the service I want to get the logged value, for a particular property, at that time. The property is logged in a value stream

To do this I need to retrieve the last logged entry prior to the time  stamp I pass in as an input parameter. Currently I use QueryNamedPropertyHistory service using the input time stamp as the end date parameter for the query. This works for now while there aren't many entries in the log. The problem will come when the log has thousands of entries.

Unfortunately QueryNamedPropertyHistory ​only has an end date parameter. If there was a start date parameter I could use my time stamp as the startDate and some date further in the past as the endDate, so it would search backwards. It seems like there ought to be a simple way to get the last entry before a given time stamp.

Does anyone have any ideas?

Thanks in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
ankigupta
5-Regular Member
(To:khayes1)

HI Kieron Hayes​,

QueryNamedPropertyHistory has both StartDate and EndDate Parameter as input.

I think you can set the MaxItems as 1 and oldestFirst as false and endDate to get the last entry before a given time stamp.

View solution in original post

2 REPLIES 2
ankigupta
5-Regular Member
(To:khayes1)

HI Kieron Hayes​,

QueryNamedPropertyHistory has both StartDate and EndDate Parameter as input.

I think you can set the MaxItems as 1 and oldestFirst as false and endDate to get the last entry before a given time stamp.

khayes1
13-Aquamarine
(To:ankigupta)

Hi Ankit,

thanks for your reply. You are correct, there are both start and end input parameters. Not sure why I thought there was only an end date .

Kieron

Top Tags