Time filter for object class data source

Hi! I’m trying to filter my data based on input. I want to be able to quickly select last week etc. OR select a specified timerange. The default should be “last week”.
This is my current setup:

This function should translate “Last week” to a datetime, but does not work. I think the function is stolen from an Appfarm showroom app:

Have tried this but it does not satisfy my needs:

So what is the best way to filter a datasource based on a time-range?
And how can I set a condition where you can either select a specific time-frame or “last week”, “last month” etc.?

Hi (and welcome to the Community!)

A few pointers for a possible solution:

  • You would need three app variables, Time From (datetime), Time To (datetime) and the Time Filter enum-property (ie. Last Hour, Last Day, etc.) The value on create for these properties when opening the app should be Time From = Today - 1 week, Time To = Now for the datetime filter properties, and then Last Week for the Time Filter property.
  • The App Variables.Time Filter property in the UI should have an On Value Change event that triggers an action. The action changes the App Variables.Time From and App Variables.Time To datetimes based on what is the current value of App Variables.Time Filter (using conditions and update action nodes).
  • And then you can filter your Tekniske Hendelser-data source based on the two datetime properties (as you have done).
  • To support a custom time range, you would add the App Variables.Time From and App Variables.Time To as datetime picker components in the UI (as you have done).

The approach with the function in your example is not necessary for this case and would be a more complex approach as you want to filter based on two properties (and you want to be able to select a specific time range as well), and not one as the example your are referring to is using.

For future references; the function did not work instantly because you have not added any function parameters or the Moment library to it (right-hand side where it says Function Parameters and No parameters added. This can be done in the Select Parameters list on the left-hand side. In addition for this specific approach to work, the App Variable would have to be a function type instead of value type.


Thanks for fast reply. The only thing now is how to set the default value of the appvariables to -1 week
Have tried a number of approaches, though it is unclear what goes wrong. Can i have code in the variable-parameters? And if so, is it in Java?

Currently I use a workaround where default value is “null”, with an action “on view load” that sets the value using moment to return “last week” as datetime. However it would be much cleaner if I could set the default value directly


To set the Value on Create values you click on the three dots and select Today or Now depending on your use. You can then use the Value Processor by clicking the three dots again and select Value Processor and create a chain of modifications to the base value.

To get Today - 1 week you would select Today as the Value on Create and then use the Value Processor to subtract 1 week.

1 Like