Fetch data from most recent previous visit

I have a form which can be filled multiple times per user. What I need to do is at each visit, I need to know how many visits has been made by that person previously and I want to fetch the data for a field from the most recent completed visit. I can use query to get the count of person IDs using async_assign, so that is not a problem. I can also query data for a specific field, but what I am not getting is how to get data only for the most recent visit where _savepoint_type is COMPLETE.

Hi @Mandy_Sin! You’re definitely on the right track with what you’re thinking so far. You should be able to do a query for the date too, I think the maximum date maybe? The _SAVEPOINT_TIMESTAMP saves the date. I haven’t done this exactly, but have generally done queries taking the maximum year that’s complete for example, using async_assign_max. There may be a more efficient way to do it, but I usually do this in a couple of steps, one query to calculate the maximum timestamp that’s complete with the matching id and assign that to a variable, and then a next step to run a query for whatever data you need from a specific field that has that timestamp for the same id.

Never realized I could make use of _SAVEPOINT_TIMESTAMP. Thank you so much for pointing me in the right direction. Like you said, not the most elegant way to do it, but will get the job done. So, thanks!

2 Likes