Date Picker Template - Set todays date on view load

I am attempting to create a template to set date ranges for views that contain tables (and charts later on).

I am having trouble being with having the view default with todays date when the page is loaded.

I have 2 custom properties which are used as parameter values within the named query:
view.custom.selectedStartDate
view.custom.selectedEndDate

I have 6 Buttons which trigger a script to set the date range above:
Today
Yesterday
Next Day
Previous Day
Day Shift
Afternoon Shift

I have 2 Date Time Pickers also:

This all works up to here.

To try and initialize the date I setup a view OnStartUp script but found it will set the date but then when one of the buttons are clicked it creates a loop where the dates start fighting against each other until I leave the view. I tried adding a custom bool called self.custom.intiitalize to only get the script to run once but it does not work.

I also tried binding the custom date params to an expression with todays date but theses also fight against each other.

I have attached an overall layout of inputs in the view for reference. I feel like I am missing something very simple here.

I think it's not the onStartup Script script that is causing the issue. You can remove the custom bool.

Do you have your DateTime Picker binded to view.custom.selectedStartDate and
view.custom.selectedEndDate?
I think, it's the onChange Script in the DateTime picker that is causing the issue. When you press a button it triggers the onChange script in the DateTime Picker.
Instead, just bi-directionally bind it to custom params.

1 Like

Get rid of those on change scripts, they are overcomplicated and unnecessary. You're also comparing currentValue to preciousValue which are basicqualifiedvalue objects and will always be different. Don't use a start up script.
Simply bind the date time picker values to expressions that get your dates, making sure to set them not to poll within the now function. They will fire once on load and never again.

As an aside, you can do this for any other onload values as well by using an expression that has no changing reference in it

2 Likes

Thanks Cose_Peter1 and Nminchin.

Removed the startup script, tag value change scripts, selcted bi directional, and edited to poll once as suggested and finally working!

1 Like