How do I call a project library script from an expression binding?

I am attempting to use a simple project library script in an expression binding. Perspective doesn't seem to like doing so.

Is there a way to do this? I did use the ScriptName.functionName(param) syntax.

Use the runScript() expression function. If passing arguments, read its instructions and examples carefully.

2 Likes

Note that the Expression language is its own thing and though similar is some aspects is not the same as Jython (the scripting language).

The Manual is your friend.

https://docs.inductiveautomation.com/display/DOC81/Expression+Language+and+Syntax

1 Like

The manual says:

// Preferred syntax.

runScript( "textScript.myFunc" , 0 , "Hello Again" , "See ya later" )

I am attempting to use runScript() as getting a value from a project library script (string), by sending an integer in the parameter field for a named query:
runScript("CustomSwitchFunc.getZoneName", {view.params.zone})
I get 0 records, when 3 is expected.

runScript(CustomSwitchFunc.getZoneName, {view.params.zone})
returns configuration error.

runScript("CustomSwitchFunc.getZoneName({view.params.zone})")
returns an empty dataset

runScript("CustomSwitchFunc.getZoneName(1)")
returns the expected dataset.

runScript("CustomSwitchFunc.getZoneName", 1)
returns an empty dataset

runScript("CustomSwitchFunc.getZoneName()", {view.params.zone})
empty dataset

runScript("CustomSwitchFunc.getZoneName", "{view.params.zone}")
empty dataset

So... what am I missing?

Edit:
and this runScript("CustomSwitchFunc.getZoneName('" + {view.custom.zone_test} +"')")
returns an empty dataset

If you're using the preferred form (separate arguments) you must specify the poll rate parameter; that's the zero in the example you copied.

3 Likes

As @PGriffith says.

This one returns 0 records because, the zone parameter is interpreted as the polling rate and the default value for the zone parameter in the function is assumed, probably None in this case. How many records would the function return for Zone 0?

Try this instead:

runScript("CustomSwitchFunc.getZoneName",0,{view.params.zone})

Definitely a :man_facepalming: moment!

Phil said read it carefully, I read but didn't "see" the poll param; the brain said "Oh, it's optional, just ignore it."

Thanks, @pturmel , @lrose and @PGriffith for your patience with people, like me, who sometimes overlook the obvious :sweat_smile:

1 Like

For future reference, afaik the expression language does not support keyword arguments, so the only time that optional parameters are optional is if you are not providing any optional parameters or they are not followed by any supplied value.

2 Likes