Run workflow when field value > state value

Hi everyone !

I want to change a “status” field from “completed” to “pending” 18h after a user last clicked on a button. When the button is clicked, the value in a field called “action +18 hours” is set to the current date and time plus 18 hours (field type = date).

I created a state (“date-and-time”) that is simply the current date and time, updated every second.

Put simply, I want to create a workflow that runs when the state “date-and-time” is greater than the field “action +18 hours”. The workflow would change the “status” field from “completed” to “pending” . I do not know how to create this workflow, whic is why I created this topic.

Thanks for your help !

There’s a workflow event called “Do when condition is true” and make sure to change the “Run this” to Everytime. Then you can basically set up the condition to whatever you want. Then if the condition is true make the first action “Make changes to a thing” and change the status.

This would only run when someone is on the page, is that fine or did you want something in the background always checking?

Hello Tyler,

Thank you for answering.
It is fine if the workflow only runs when the user is on the page.

I had already tried the option you suggests, but I could not figure out what to write it the “only when” box. I am using “do a seach for” to get to the data type (“Événements Anticipés”), and then to the field “DateTime +18 hours” (which is the same as “action +18 hours” in my message above), but there is no mathematical operator at this point, so I cannot write lower than (“<”) the “date-and-time” state. See the screenshot attached to this message.

Do you have an idea what I should write in the “Only when” box ?

Thanks !

You probably don’t need to do any searches. If your thing is the current page’s thing then just do Current page's Événements Anticipé's DateTime < Current Date/Time + 18 hours

You might have to flip the < sign around or move the +18 hours to the other side, not sure you’ll have to test it.

Or are you looking for this workflow to check all events not just the current page’s?

The workflow must apply to each row of the data type “Événements anticipés” . Each row will have a different value for the “DateTime +18 hours” field and each row will be either “pending” or “completed” (status field).

The simpliest solution would be to add the workflow directly in my repeating group element (specifically, in a text element within the repeating group), but then the workflow would only run when the text element is clicked, and I do not know how to change that.

Are you on a paid plan? This sounds like something that would best be in the backend workflows. They are server-side things that can run in the background.

You can setup an API workflow that runs through all the events and check each date individually. Then either have a button a user clicks to initiate this process or you can have it trigged everyday at 12AM for example.

I am currently on the free plan. The solution you propose is interesting, but the workflow would have to run every minute or so ideally, I am not sure if that is possible with an API.

Is there a way to attach a workflow to an element, but make it run every X number of seconds instead of on click ? Probably not. That is a tricky one !

There is a workflow event called “Do every 5 seconds” but once you click it you can put your own number of seconds. But it’s the same thing it would on the client’s page so if no one is looking at that specific thing the status would not update.

Let me test something on my app there might be a way to run this in your browser instead of the backend. One sec

Okay this might be super janky but you’ll have to test it:
In the workflows create 2 new Custom Events, I called one step1 and the other one step2 but you can rename those.

Click the add new parameter and call it “list” and make the type your event. And check the box to make it a list. (for both the step 1 and step 2 events)

Then I set up “On Page load” it triggers the event step 1

Try that setup. It searches for the list of events with the status “Complete” sends that list to Step1, if the first item in the list’s date + 18hrs is less than current time, it sets the status to “Pending”. Then sends the list to step 2 (but removes the first item that was processed) then step 2 sends that list right back to Step 1 and the process repeats. As the process loops it keeps removing the first item until the :count is 0. Then the “Schedule step2” won’t trigger and the loop stops.

This might be super slow or will work fine :sweat_smile: But try it out. If this works we can figure out how to show a visual of the process running so you know when it’s done.

This is a similar process that would run in the backend but with a few workarounds to work client side.

You could also create a new reusable element and make the data type Événements anticipés

Then the workflows for the reusable element make one “Do every 5 seconds” , then Make changes to a thing [your reusable elemenets name]s Événements Anticipé's with the condition [your reusable elemenets name]s Événements Anticipé's DateTime < Current Date/Time + 18 hours

Then drag that reusable element into your repeating group list of events and set it’s data type to Current cell's Événements Anticipé

I think that would work as long as your repeating group is showing all events you want checked

Hi Tyler,

Sorry for the delay.

This option sounds like it should work, but it does not (I changed the coundown to 20 seconds instead of 18 hours to test this solution). Do you have any idea why it does not work ?

I created a reusable group with the type “Événements anticipés”, then I added two workflows in it.

(“Pour traitement” in this case is the equivalent of “pending”)

I also tried placing the “only when” condition directly in the “Make change to Événements anticipés” box, without success.

If there is no way to make this work, I will give it a shot with your first (but arguably more complex) solution.

Thank for your help !

I don’t think the Current date/time custom state is needed because every 5 seconds it would get the current date/time anyways. Just a sidenote but not the main reason it’s not working…

On your main page you said you have a repeating group with a list of all your Completed events?
Did you drag that reusable element into the cell of the repeating group, then make sure to set the data source of the reusable element to the current cell’s thing?

It works :open_mouth: !!

I’m very happy with that.

Thank you for your help :slight_smile:

Have a lovely day/evening.

1 Like

Great :+1:

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