[Solved] Time triggers

Hi,

I am creating a time blocking app, and I want to only show sessions that start after the current time.

While I can get the page to do that on load, as the time changes, I would like the page to remove sessions whose start times become after the current time as the time passes their start time.

e.g. a session is due to start at 4.20. I load the page at 4.15 and the session is visible. When it gets to 4.21, the 4.20 session disappears.

How do I do this?

Thanks!

Use whatever the condition you’re using during page load on the list of sessions

If you’re using smth like “sessions time>current date” on page load, use the same on the repeating group of sessions

If this doesn’t help, you may wanna provide more details like how you’re storing sessions and how you’re displaying them.

1 Like

What you suggest is (I believe) exactly what I am doing in the repeating group, nowhere else. So, I am using this in the repeating group:

which provides me with sessions up to 5 minutes late. This doesn’t refresh with time, so when the time passes, if I don’t reload the page, then sessions I want to have disappeared are still visible.

Sessions are stored with a start time, and that start time is displayed.

I have tried adding a condition on the group within the repeating group, but it doesn’t seems to automatically cause the group to disappear when the start time (+5 minutes) has passed:

image

I have now tried the workflow “Do every 5 seconds” - “Refresh page”

This is working, but every 5 seconds, the page disappears and reappears. Is there a way to refresh the page (or get the old data to disappear) in a way that doesn’t make the page blink?

Thanks

A very similar question to this came up here in the forum recently with a few valid suggestions for a solution….

But basically, you need to update the time every second (or every 5 seconds, or whatever), but you don’t want to be doing a new database search every time you do that or it will cost a lot of WU…

So one solution was to load a large set of data to the page first, and the filter it client side based on the real-time time variable.

Obviously, whether that will work in your case will depend on many specifics of your app and data, but it might be one option (probably the one I’d recommend).

2 Likes

I like the idea of filtering it client side, but how do I get the filtering to happen in real time?

I have tried putting in a condition that the information only shows when the start time (+5 minutes) is greater than the current time, but that only seems to update when the page refreshes, rather than automatically as the time changes.

You just need to update the current date/time in real time (i.e. every second) and use that value in your filter.

There must be a thousand forum posts on how to do that - but to summarise, you can use a group with a Date content-type, or a custom state of type Date, and run a do every x seconds workflow to update it.

Or you can use some custom JavaScript with setInterval to output the date value (or use one of the several plugins that do this for you).

In any case, the end result is the same - the current date/time kept up to date in real-time.

You can then use that value as a constraint in your client-side filtering of the data which you’ll have already loaded to the page (just make sure you have already loaded it to the page - otherwise you’ll be doing a fresh database search every second which will consume a lot of WUs).

1 Like

So if I understand you, I have set a group (in my case, my Group Countdown) to

Type of content: Date
Data source: Current date/time

image

and workflow of

Do Every second
Reset Group Countdown

++++

Loading the data, I presume the following loads all the data?

I have a repeating group, type Period, data source Search for Periods (filtered for the current user, etc)
image

++++

For the constraint, I have used a conditional for visibility - does this reference that date/time though, or some other? Or am I supposed to reference the current date/time some other way?
image

Thanks!

That doesn’t work… (although I can see why you might think it would)…

you actually have to set the current date/time every seconds using a ‘Display Data’ action, rather then ‘Reset Data’ (which just resets it to its original value, which was set when the group was first loaded).

Loading the data, I presume the following loads all the data?

If that’s the data you’re intending to load, then yes - but just make sure you don’t include any date/time constraints relating to the real-time date value in the search.

Then just refer to that RG’s list of things in the main RG you using (although it might be better to use a custom state rather than a RG to load the initial data).

For the constraint, I have used a conditional for visibility - does this reference that date/time though, or some other? Or am I supposed to reference the current date/time some other way?

A conditional won’t work here… you need to use a constraint on a filter of the initial data.

So, lets assume you’re loading the initial data into a custom state (presumably all those which start after the current date/time, or maybe just some of those, depending on the size of your database)…

Then, in your RG, set the data source to that custom state’s value: filtered - then set the start time constraint according to the real-time data value (not the current date/time).

1 Like

Hmm, ok, so I have tried that, but I am getting the error that I must both display data, and that the data to display should be empty, which makes no sense to me…

What is even more confusing is that I have tried to do the same thing on a different page, and there I am not getting this error…

image

+++

I have created a custom state of all periods,

image

which sets on page load.

However, doing so seems to make the page refuse to open the popup for adding a new session.

I have tried to run it step by step to find out why, but it because the popup never emerges, the debugger shows nothing…

What am I doing wrong? Why would adding a custom state stop the page from working, or am I setting the custom state wrong?

+++

I am confused. You say that I

but if I am filtering my search of them to include only those that start after the current date/time, surely I would be doing just that?

Sorry, I have spent the whole day on this and now the page isn’t working at all!

Have you defined the content-type of Date on the Group? (certainly, it looks like you haven’t from the issue checker message).

What am I doing wrong? Why would adding a custom state stop the page from working, or am I setting the custom state wrong?

It shouldn’t make any difference, so if that’s the case it must be something else that’s wrong (although in your screenshot you’re not setting any value to the custom state at all).

but if I am filtering my search of them to include only those that start after the current date/time, surely I would be doing just that?

No…

If you put the constraint on the search, then the search will be repeated every second.

I’m saying DON’T do that.

Instead, apply a filter to the data that’s already on the page (in the custom state), so you only do the search once, and then filter the results client-side.

1 Like

I’m not sure what you mean. Which group are you suggesting I set content type to date? Do you mean the custom state?

I thought I was setting the custom state to be my list of periods / sessions? Setting the custom state to be a list of dates gives me this error, presumably because I need the list of sessions to be somewhere…

Thanks!

No I don’t mean Custom State… I mean content-type. If you’re using a group for this then you need to set the content-type of that Group to Date before you can display Date data in it. (although you could use a Custom State instead for this, it really makes no difference).

I thought I was setting the custom state to be my list of periods / sessions?

Maybe you thought you were… but (at least in the screenshot you posted) you haven’t set anything.

Setting the custom state to be a list of dates gives me this error, presumably because I need the list of sessions to be somewhere…

Obviously, if you RG is intended to show a list of Periods, the data source must be a list of Periods…

So I can’t really work out what you’re trying to do from that screenshot? (the Custom State you’re showing is a list of Dates? - what is that for? and how does it relate to anything here?)

1 Like

I have set my countdown element to type date, which seems to have removed the error (although I haven’t tested it yet because setting the state still breaks the page) .

I see - I had set its value, and that stopped the page from working; so I then took away its value (the screenshot shows that) and the page still doesn’t work.

Either way, putting the set state instruction into the page stops the page from doing anything when I try to open the popup. Could it be interacting with something else? Certainly the page work until I try to set that state, it is only once I put that instruction in that the page ceases to function…

Ok, so I have got my list of sessions loaded into a custom state.

I have a countdown timer counting down to the start of the first session.

I cannot seem to get the page to update the information when the current time passes the session start time. When the countdown gets to zero (i.e. the 1st session’s start time is the current time), no matter what I do, the 1st session stays there rather than being replaced with the next session, and the countdown stubbornly refuses to restart.

My best guess was this, but nothing doing…

How else, without refreshing the page, do I get the page to update the data it is showing?

Whoop whoop, I worked it out!

I have 2 custom states:

  1. the list of sessions, which is set by workflow every time the page reloads
  2. the current date / time, which is set by workflow every 1 second

I needed a filter to make everything on the page show as it should. That filter is an advanced one, looking to the current date / time within the custom state.

E.g. start countdown with an end date of the the first session’s start time, and the filter to determine which is the first session is:
Advanced: current date / time custom state < this session’s start time.

My repeating groups used the same advanced filter.

Thanks @maheshkasindi and particularly @adamhholmes for your help

2 Likes

This topic was automatically closed after 70 days. New replies are no longer allowed.