# My first script... does not work

**URL:** <https://forum.inductiveautomation.com/t/my-first-script-does-not-work/9591>\
**Category:** Ignition\
**Created:** [January 22, 2015, 8:42pm UTC](https://forum.inductiveautomation.com/t/my-first-script-does-not-work/9591 "2015-01-22T20:42:54Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![CJVR](https://avatars.discourse-cdn.com/v4/letter/c/0ea827/32.png) [@CJVR](https://forum.inductiveautomation.com/u/CJVR)\
**Post date:** [January 22, 2015, 8:42pm UTC](https://forum.inductiveautomation.com/t/my-first-script-does-not-work/9591/1 "2015-01-22T20:42:54Z")

</div>

I am trying to set the Date (immediate) of a Calendar object when a window is first opened. So I create a script on the internalFrameOpened event of the window. I first tried the Set property ta\b. This got me the path to the property but there was no way to get the date. So, I wrote this scropt myself after playing with the Script Playground:

`import datetime
system.gui.getParentWindow(event).getComponentForPath('Root Container.Calendar').date = datetime.datetime.now().date()`

The script fires at the correct time but I get a java error:

```auto
TypeError: can't convert datetime.date(2015, 1, 22) to java.util.Date
```

This seems like a basic question but I have never used Python or Java so I am really stuck.

Thanks,

---

<div class="post-metadata">

**Author:** ![CPowell](https://avatars.discourse-cdn.com/v4/letter/c/a183cd/32.png) [@CPowell](https://forum.inductiveautomation.com/u/CPowell)\
**Post date:** [January 22, 2015, 8:55pm UTC](https://forum.inductiveautomation.com/t/my-first-script-does-not-work/9591/2 "2015-01-22T20:55:25Z")

</div>

You can just bind now() to the date in the calendar object.

```auto
now()
```

You can also do dateArithmetic like so.

```auto
dateArithmetic(now(0), -1, "day")
```

Cheers,  
Chris

---

<div class="post-metadata">

**Author:** ![CJVR](https://avatars.discourse-cdn.com/v4/letter/c/0ea827/32.png) [@CJVR](https://forum.inductiveautomation.com/u/CJVR)\
**Post date:** [January 22, 2015, 9:04pm UTC](https://forum.inductiveautomation.com/t/my-first-script-does-not-work/9591/3 "2015-01-22T21:04:29Z")

</div>

Binding now() causes the calendar to revert back to now after another date is picked. I am looking to set the date when the project first loads.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [January 22, 2015, 9:26pm UTC](https://forum.inductiveautomation.com/t/my-first-script-does-not-work/9591/4 "2015-01-22T21:26:50Z")

</div>

I ended up running a database query with polling mode off. In MySQL:

```auto
SELECT curdate()
```

---

<div class="post-metadata">

**Author:** ![jpark](https://avatars.discourse-cdn.com/v4/letter/j/a88e57/32.png) [@jpark](https://forum.inductiveautomation.com/u/jpark)\
**Post date:** [January 22, 2015, 10:12pm UTC](https://forum.inductiveautomation.com/t/my-first-script-does-not-work/9591/5 "2015-01-22T22:12:09Z")

</div>

You can use

```auto
now(0)
```

0 is the pollrate

---

<div class="post-metadata">

**Author:** ![CJVR](https://avatars.discourse-cdn.com/v4/letter/c/0ea827/32.png) [@CJVR](https://forum.inductiveautomation.com/u/CJVR)\
**Post date:** [February 3, 2015, 4:01pm UTC](https://forum.inductiveautomation.com/t/my-first-script-does-not-work/9591/6 "2015-02-03T16:01:29Z")

</div>

I used the Set Property tab. It generated this sctript:

`value = u'now(0)'
system.gui.getParentWindow(event).getComponentForPath('Root Container.Calendar').date = value
`  
When I run the app I get this error:

`TypeError: can't convert u'now(0)' to java.util.Date
`  
I am just trying to set the current date of the calendar component to today. What am I doing wrong?

Thanks,

---

<div class="post-metadata">

**Author:** ![CPowell](https://avatars.discourse-cdn.com/v4/letter/c/a183cd/32.png) [@CPowell](https://forum.inductiveautomation.com/u/CPowell)\
**Post date:** [February 3, 2015, 4:57pm UTC](https://forum.inductiveautomation.com/t/my-first-script-does-not-work/9591/7 "2015-02-03T16:57:14Z")

</div>

You want to bind the now(0) expression to the Date Property of the Calendar Component.  
Like so…

 ![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/e/ea23e385066dc456c70b330acd81f1ff41be0333.PNG)  

Cheers,  
Chris

---

<div class="post-metadata">

**Author:** ![CJVR](https://avatars.discourse-cdn.com/v4/letter/c/0ea827/32.png) [@CJVR](https://forum.inductiveautomation.com/u/CJVR)\
**Post date:** [February 3, 2015, 5:47pm UTC](https://forum.inductiveautomation.com/t/my-first-script-does-not-work/9591/8 "2015-02-03T17:47:31Z")

</div>

That worked. What I am really trying to get to is setting the calendar to midnight Monday of the current week. Until I have time to muck around with the scripting some more I will use this. I did format the result of now(0) to just the date so I am getting midnight as my date. Thanks.
