# Expression and runScript problem

**URL:** <https://forum.inductiveautomation.com/t/expression-and-runscript-problem/98666>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [November 15, 2024, 3:21pm UTC](https://forum.inductiveautomation.com/t/expression-and-runscript-problem/98666 "2024-11-15T15:21:39Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aiasa21](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@Aiasa21](https://forum.inductiveautomation.com/u/Aiasa21)\
**Post date:** [November 15, 2024, 3:21pm UTC](https://forum.inductiveautomation.com/t/expression-and-runscript-problem/98666/1 "2024-11-15T15:21:39Z")

</div>

Hello everybody, I'm trying to make work a runScript expression in the UDT.

The function has 4 parameters:

1. integer
2. integer
3. datetime
4. datetime

I set the polling to 3000ms, and parameter has request from the function but it doesn't work.

`runScript("myPath.myFunc(1, 1, {[.]StartDate}, now())", 3000)`

If i run the function in the script console it works.

Where did I go wrong?

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [November 15, 2024, 3:28pm UTC](https://forum.inductiveautomation.com/t/expression-and-runscript-problem/98666/2 "2024-11-15T15:28:31Z")

</div>

The arguments go after the poll rate, not inside the function string. You are trying to use legacy formatting with expressions/paths that are not evaluating because they are apart of the string.

[runScript | Ignition User Manual](https://docs.inductiveautomation.com/docs/8.1/appendix/expression-functions/advanced/runScript)

Try this

```python
runScript("myPath.myFunc", 3000, 1, 1, {[.]StartDate}, now(0))

```

_ **Note** _ that runScript expressions should only call scripts that have very short, like a few milliseconds, execution time. Otherwise, you can delay other tag evaluations.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [November 15, 2024, 3:36pm UTC](https://forum.inductiveautomation.com/t/expression-and-runscript-problem/98666/4 "2024-11-15T15:36:19Z")

</div>

> [@dkhayes117](#):
>
> _ **Note** _ that runScript expressions should only call scripts that have very short, like a few milliseconds, execution time. Otherwise, you can delay other tag evaluations.

~~I'm not sure this applies to expression tags. I think perhaps you're mixing this up with `Tag ValueChange scripts` which have that restriction because they run in a fixed pool.~~

EDIT: Nope, you were right.

---

<div class="post-metadata">

**Author:** ![Aiasa21](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@Aiasa21](https://forum.inductiveautomation.com/u/Aiasa21)\
**Post date:** [November 15, 2024, 3:37pm UTC](https://forum.inductiveautomation.com/t/expression-and-runscript-problem/98666/5 "2024-11-15T15:37:46Z")

</div>

Thanks for the help and the clarification about the use of runScript.

I try your code but I have this error:

```python
[null, Error_ExpressionEval("Error executing script for runScript() expression:myPath.myFunc"), Fri Nov 15 16:36:18 CET 2024 (1731684978389)]

```

---

<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:** [November 15, 2024, 3:39pm UTC](https://forum.inductiveautomation.com/t/expression-and-runscript-problem/98666/6 "2024-11-15T15:39:06Z")

</div>

> [@lrose](#):
>
> you're mixing this up

Expression tags also run in a pool, also of three threads, and runScript() uses that. Stalls there will kill your other expression tags instead of all your tag events.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [November 15, 2024, 3:41pm UTC](https://forum.inductiveautomation.com/t/expression-and-runscript-problem/98666/7 "2024-11-15T15:41:28Z")

</div>

> [@pturmel](#):
>
> Stalls there will kill your other expression tags

Did not know that. Thanks.

> [@Aiasa21](#):
>
> I try your code but I have this error:

@Aiasa21

Is `myPath.myFunc` a real function in your **Gateway Scripting Project**?

---

<div class="post-metadata">

**Author:** ![Aiasa21](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@Aiasa21](https://forum.inductiveautomation.com/u/Aiasa21)\
**Post date:** [November 15, 2024, 3:44pm UTC](https://forum.inductiveautomation.com/t/expression-and-runscript-problem/98666/8 "2024-11-15T15:44:46Z")

</div>

> [@lrose](#):
>
> Is `myPath.myFunc` as real function in your **Gateway Scripting Project**?

Yes, I'm making the test with them so to avoid problems.

I try also with this just to test:

```python
runScript("myPath.myFunc", 3000, 1, 1,dateArithmetic(now(0), -5,"days"), now(0))

```

This is the code in the script console that actually works:

```python
par_data_inizio = system.date.addDays(system.date.now(), -10) 
par_data_fine = system.date.now()

myPath.myFunc(1, 1, par_data_inizio, par_data_fine)

```

I have this float as result:  
`91.89272727272727`

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/e/bea2c096b81f6aa4b6c6007f679a1478af0aa0e5.png)

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [November 15, 2024, 3:52pm UTC](https://forum.inductiveautomation.com/t/expression-and-runscript-problem/98666/9 "2024-11-15T15:52:44Z")

</div>

The project script must exist in your project that is designated as your _ **global scripting project** _ because tag expressions evaluate on the gateway. Scripts in other projects cannot be directly called from the gateway scope.

---

<div class="post-metadata">

**Author:** ![Aiasa21](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@Aiasa21](https://forum.inductiveautomation.com/u/Aiasa21)\
**Post date:** [November 15, 2024, 3:55pm UTC](https://forum.inductiveautomation.com/t/expression-and-runscript-problem/98666/10 "2024-11-15T15:55:39Z")

</div>

I understand, I need to figure out this.

Thank you very much for your help and have a nice day.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [November 15, 2024, 3:56pm UTC](https://forum.inductiveautomation.com/t/expression-and-runscript-problem/98666/11 "2024-11-15T15:56:30Z")

</div>

> **[Project Library | Ignition User Manual](https://www.docs.inductiveautomation.com/docs/8.1/platform/scripting/scripting-in-ignition/project-library#gateway-scripting-project)**
>
> Scripts under the Project Library are a project-based resource that allows user created Python scripts to be configured. Objects and functions created in a Project Library script can be called from anywhere in the project. Project Library scripts are...
