# Date Picker Template - Set todays date on view load

**URL:** <https://forum.inductiveautomation.com/t/date-picker-template-set-todays-date-on-view-load/103024>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [February 28, 2025, 3:20am UTC](https://forum.inductiveautomation.com/t/date-picker-template-set-todays-date-on-view-load/103024 "2025-02-28T03:20:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![James\_Toor](https://avatars.discourse-cdn.com/v4/letter/j/ce73a5/32.png) [@James\_Toor](https://forum.inductiveautomation.com/u/James_Toor)\
**Post date:** [February 28, 2025, 3:20am UTC](https://forum.inductiveautomation.com/t/date-picker-template-set-todays-date-on-view-load/103024/1 "2025-02-28T03:20:56Z")

</div>

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.

 ![Date Picker Template drawio](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/3/831aec65a5820d6e891d08bf1a35ba67ecb0a92a.png)

---

<div class="post-metadata">

**Author:** ![Cose\_Peter1](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cose_peter1/32/79174_2.png) [@Cose\_Peter1](https://forum.inductiveautomation.com/u/Cose_Peter1)\
**Post date:** [February 28, 2025, 5:02am UTC](https://forum.inductiveautomation.com/t/date-picker-template-set-todays-date-on-view-load/103024/2 "2025-02-28T05:02:17Z")

</div>

> [@James\_Toor](#):
>
> 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 think it's not the onStartup Script script that is causing the issue. You can remove the custom bool.

> [@James\_Toor](#):
>
> I have 2 Date Time Pickers

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.

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [February 28, 2025, 6:59am UTC](https://forum.inductiveautomation.com/t/date-picker-template-set-todays-date-on-view-load/103024/3 "2025-02-28T06:59:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![James\_Toor](https://avatars.discourse-cdn.com/v4/letter/j/ce73a5/32.png) [@James\_Toor](https://forum.inductiveautomation.com/u/James_Toor)\
**Post date:** [March 17, 2025, 7:25pm UTC](https://forum.inductiveautomation.com/t/date-picker-template-set-todays-date-on-view-load/103024/4 "2025-03-17T19:25:54Z")

</div>

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!
