# Perspective - How to initialize a datetime input from script

**URL:** <https://forum.inductiveautomation.com/t/perspective-how-to-initialize-a-datetime-input-from-script/23874>\
**Category:** Ignition Early Access\
**Created:** [April 5, 2019, 1:24pm UTC](https://forum.inductiveautomation.com/t/perspective-how-to-initialize-a-datetime-input-from-script/23874 "2019-04-05T13:24:13Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![chi](https://avatars.discourse-cdn.com/v4/letter/c/0ea827/32.png) [@chi](https://forum.inductiveautomation.com/u/chi)\
**Post date:** [April 5, 2019, 1:24pm UTC](https://forum.inductiveautomation.com/t/perspective-how-to-initialize-a-datetime-input-from-script/23874/1 "2019-04-05T13:24:13Z")

</div>

I’m searching for a way to initialize datetime inputs on session startup.

I tried the following code in a containers startup event:

```auto
	now = system.date.now()
	self.getChild('dt-ende').props.value = now.getTime()
	self.getChild('dt-anfang').props.value = system.date.addHours(now, -8).getTime()

```

This fails, because at that time there is no `value` property:  
`AttributeError: 'com.inductiveautomation.perspective.gateway.script' object has no attribute 'value'`  
The value property appears only after a value has been entered or selected.  
Is there something i’m missing?

Another question: What is the best place to put a change script for this component? A change script for the `value` property is deleted when this property is deleted.

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [April 5, 2019, 2:35pm UTC](https://forum.inductiveautomation.com/t/perspective-how-to-initialize-a-datetime-input-from-script/23874/2 "2019-04-05T14:35:27Z")

</div>

~~The DateTimeInput Component has no `value` property before a value has been selected. Try assigning the value you want into one of the formatted values available to you.~~  
A team-member pointed out that you’re attempting to do this in a Session startup script, which is not going to work, as the View may not even technically exist, and even if it does, the Session Startup script would not be the place to do this.

Select your View node, then right-click the View node and select “Configure Events”. Place your code into a VIEW Startup script and it should work, assuming the DateTime Inputs are in the root Container, and not any deeper.

---

<div class="post-metadata">

**Author:** ![chi](https://avatars.discourse-cdn.com/v4/letter/c/0ea827/32.png) [@chi](https://forum.inductiveautomation.com/u/chi)\
**Post date:** [April 5, 2019, 3:06pm UTC](https://forum.inductiveautomation.com/t/perspective-how-to-initialize-a-datetime-input-from-script/23874/3 "2019-04-05T15:06:32Z")

</div>

> [@cmallonee](#):
>
> Try assigning the value you want into one of the formatted values available to you.

Ok, thank you. I was hoping for a locale independent way to assign a value. Working with the formatted value will make the script more complicated when i have to deal will multiple languages.  
Maybe you can add the millisecond time as a feature in one of the next versions.

---

<div class="post-metadata">

**Author:** ![silverbacknet](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/silverbacknet/32/7385_2.png) [@silverbacknet](https://forum.inductiveautomation.com/u/silverbacknet)\
**Post date:** [April 5, 2019, 9:45pm UTC](https://forum.inductiveautomation.com/t/perspective-how-to-initialize-a-datetime-input-from-script/23874/4 "2019-04-05T21:45:31Z")

</div>

> [@chi](#):
>
> > [@cmallonee](#):
> >
> > Try assigning the value you want into one of the formatted values available to you.
> 
> Ok, thank you. I was hoping for a locale independent way to assign a value. Working with the formatted value will make the script more complicated when i have to deal will multiple languages.  
> Maybe you can add the millisecond time as a feature in one of the next versions.

system.date.fromMillis() and system.date.toMillis()? But do see @cmallonee's edit about what's either an initialization race condition or undefined behavior.

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [April 5, 2019, 10:18pm UTC](https://forum.inductiveautomation.com/t/perspective-how-to-initialize-a-datetime-input-from-script/23874/5 "2019-04-05T22:18:18Z")

</div>

It’s not exactly a race condition per se…

Views do not exist in a session unless they are part of your current “Page’s” Page Configuration in some manner. Right now, that comes down to a child component (Embedded View or the descendant Embedded Views of any Embedded View), a Popup (but only if it’s open), or a Docked View which is attached to the Page Configuration in use (and because of a couple of open bugs, only the \*most recently opened Docked View\_ if there are more than one on a given side).

If a View exists in your project but it doesn’t meet one of those criteria, then the View does **not** exist _within the session_. You may not modify any values for that View or its children components, and no listeners within that View will operate.

It’s also not undefined behavior, because we know exactly what will happen; nothing.

If at any time you need to manipulate something within a View, or refer to some property within a View, then that View needs to be part of your current session or you’re going to run into NoneType references.

This is why parameter-passing and session properties are so important now.

Initialization is also possible in one-shot instances like Chi’s use-case, but that needs to be handled in the View Startup.

---

<div class="post-metadata">

**Author:** ![chi](https://avatars.discourse-cdn.com/v4/letter/c/0ea827/32.png) [@chi](https://forum.inductiveautomation.com/u/chi)\
**Post date:** [April 7, 2019, 10:05am UTC](https://forum.inductiveautomation.com/t/perspective-how-to-initialize-a-datetime-input-from-script/23874/6 "2019-04-07T10:05:47Z")

</div>

> [@cmallonee](#):
>
> A team-member pointed out that you’re attempting to do this in a Session startup script, which is not going to work, as the View may not even technically exist, and even if it does, the Session Startup script would not be the place to do this.
> 
> Select your View node, then right-click the View node and select “Configure Events”. Place your code into a VIEW Startup script and it should work, assuming the DateTime Inputs are in the root Container, and not any deeper.

Thanks for your response. My script was in the startup event of a container inside a view, so i never used a Session startup script.  
Info for others reading this: Putting the code in the **Views** startup event does not work. If the components are in the root container, the script has to be in the **root** nodes startup event.

My orginal problem was kind of self made. In an earlier version of the script i forgot the `.props` in the properties path, so accessing `self.getChild('dt-ende').value` of course caused an error.  
Then i changed that script to the version posted above and launched a session but did not click 'Save' in the designer before. I did not realize that 'Tools-\>Launch perspective' launches the last saved version of the project.
