# Passing a date to runScript()

**URL:** <https://forum.inductiveautomation.com/t/passing-a-date-to-runscript/108157>\
**Category:** Ignition\
**Created:** [July 6, 2025, 8:56am UTC](https://forum.inductiveautomation.com/t/passing-a-date-to-runscript/108157 "2025-07-06T08:56:16Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [July 6, 2025, 8:56am UTC](https://forum.inductiveautomation.com/t/passing-a-date-to-runscript/108157/1 "2025-07-06T08:56:17Z")

</div>

Expression binding (on a session.custom property):

```python
runScript('HistoryRetrieval1Day.getHistory', 0, {this.custom.startDate})

```

`{this.custom.startDate}` is today's midnight date and `typeOf({this.custom.startDate})` returns "Date".

> **HistoryRetrieval1Day script**
>
> ```python
> def getHistory(dStartDate):
> arrPaths = system.db.runNamedQuery('Retrieve UNS tag names')
> paths = []
> for p in arrPaths:
> paths.append(p[0])
> 
> return system.tag.queryTagHistory(
> paths, 
> startDate = dStartDate, 
> endDate = system.date.addDays(dStartDate, 1), 
> returnSize = -1, 
> aggregationMode = 'LastValue', 
> returnFormat = 'Tall'
> )
> 
> ```

**Script console**

```python
d = system.date.addDays(system.date.midnight(system.date.now()), 0)
print d
HistoryRetrieval1Day.getHistory(d)

```

outputs  
`Sun Jul 06 00:00:00 BST 2025`  
`Opt-Dataset [37262R ⅹ 4C]`

**The problem**  
The expression binding returns `Dataset[0 rows, 4 cols]`.

I'm probably missing something obvious. What is it?

---

<div class="post-metadata">

**Author:** ![Samuel\_Sueur](https://avatars.discourse-cdn.com/v4/letter/s/e36b37/32.png) [@Samuel\_Sueur](https://forum.inductiveautomation.com/u/Samuel_Sueur)\
**Post date:** [July 6, 2025, 9:13am UTC](https://forum.inductiveautomation.com/t/passing-a-date-to-runscript/108157/2 "2025-07-06T09:13:36Z")

</div>

Hmm.

I know this isn't your question but why do you use `system.date.addDays(...., 0)` in your script console example?

I do not have the answer but it might help if you showed your `startDate` binding ?

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [July 6, 2025, 9:22am UTC](https://forum.inductiveautomation.com/t/passing-a-date-to-runscript/108157/3 "2025-07-06T09:22:45Z")

</div>

> ... why do you use `system.date.addDays(...., 0)`... ?

So I could test yesterday by changing 0 to -1!

startDate binding is  
`midnight(now(0))`  
which should initialise it to today when the application first loads.

Thanks!

---

<div class="post-metadata">

**Author:** ![Samuel\_Sueur](https://avatars.discourse-cdn.com/v4/letter/s/e36b37/32.png) [@Samuel\_Sueur](https://forum.inductiveautomation.com/u/Samuel_Sueur)\
**Post date:** [July 6, 2025, 9:33am UTC](https://forum.inductiveautomation.com/t/passing-a-date-to-runscript/108157/4 "2025-07-06T09:33:14Z")

</div>

Yeah honestly I'm not sure.

The only thing I can think of that might have a different outcome is script console scopping.

Have you tried checking whether your Named Query `Retrieve UNS tag names` returns the same data when it's called from the expression binding and when it's called from the script console ? (Unless you've specified a particular DB in your NamedQuery rather than use the Default database).

If this is good on your end, I'll let the true experts chime in then.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [July 6, 2025, 9:37am UTC](https://forum.inductiveautomation.com/t/passing-a-date-to-runscript/108157/5 "2025-07-06T09:37:11Z")

</div>

Yes, the DB is specified in the named query.  
I too am thinking it's something funny with scoping. Let's see what comes up. Thanks.

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [July 6, 2025, 12:49pm UTC](https://forum.inductiveautomation.com/t/passing-a-date-to-runscript/108157/6 "2025-07-06T12:49:35Z")

</div>

Log the date from the function, see if there's something weird here.

Side note: you can use `arrPath.getColumnAsList(0)` to get a column as list, instead of building it yourself.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [July 6, 2025, 2:19pm UTC](https://forum.inductiveautomation.com/t/passing-a-date-to-runscript/108157/7 "2025-07-06T14:19:31Z")

</div>

Add the project name to the `runNamedQuery`. Perspective is gateway scope.
