How can I reference dynamic data in a custom state?


Could really use some help here. I’ve set up a page where a user can pull up information from the database for different periods. In the example below the current period is 22 Jan - 21 Feb. Both dates are in a seperate text field.

Schermafbeelding 2023-02-07 om 10.09.35

What I’m trying to archieve is that when the user clicks the left arrow the period changes to 22 Dec - 21 Jan. I can’t figure out how to do this :slightly_frowning_face:

What I was thinking is that the current startdate (22 Jan) should be set as the custom state, however in the element inspector I can’t reference the dynamic date of the text field. The default value should be what is in the text field (22 Jan).

Schermafbeelding 2023-02-07 om 09.59.48

So now when setting a state in the workflow as done shown below, when someone clicks the left arrow the custom state is pulled up, but since there is no default value (value is empty) nothing happens. The startdate does not change to 22 Dec.

Schermafbeelding 2023-02-07 om 10.20.45

How can I get this to work, can someone please help me?

One option is to add a workflow “on page load” and set the initial state (the value of the input, or any other value). Another option is to split your current workflow in two: one handles the case that the custom state is empty, the other handles the case that the custom state is not empty.

Thanks! Adding a workflow on page load does the trick for setting a value for the initial state. What I’m a bit worried about however is that when the time comes to wrap the entire app into one page (which is advised if I’m correct), this will not work anymore. Because the startdate needs to be filled in by the user itself. So the startdate doesn’t exist yet when the app consisting of only one page will open. I hope this makes sense. But perhaps there is a workaround?

I’ve tried your second suggestion as well, but I’m afraid I don’t understand completely. Could you please explain a bit further on how to set this up in the workflow?

If your input has a default value set the state to that default value instead of the input value.
If your input does not have a default value then your logic needs to account for the possibility of the state being empty.
The second option is like this: instead of “when button click do things” you create 2 workflows with conditions:

  • “when button click, only when state is empty, do something”
  • “when button click, only when state is NOT empty, do something else”

For now I’ve found a solution for the problem foreseen when wrapping the app into only one page. I’ve now set up the contents of the page as a group into the page where the user will fill in a start date. By doing so, I can set a initial date for the state when the user clicks on a button after he has entered a start date. I wasn’t able to do so before, because this was on another page. Since I wrap the entire app into one page anyway this seemed to be the easiest method.

Thank you very much for your help, your suggestions led my to this solution. Cheers.

1 Like

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