Expression and runScript problem

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?

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

Try this

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.

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.

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

I try your code but I have this error:

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

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.

1 Like

Did not know that. Thanks.

@Aiasa21

Is myPath.myFunc a 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:

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

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

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

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.

1 Like

I understand, I need to figure out this.

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

1 Like