runScript in expression tag

Hello,
I tried to put in an expression tag RUNSCRIPT but not working.
I enclose a photo.

the error is this:

Last Error Cause com.inductiveautomation.ignition.common.expressions.ExpressionException: Error executing script for runScript() expression:project.test.getTempAt(‘95818’) ERROR

Thanks


Expression tags only have access to the shared script namespace, as they are visible to all projects. Move your module from “project.” to “shared.”

1 Like

It works for me, but I have the script in the global “shared” namespace. I think since it’s in your project namespace the tag doesn’t know which project to look at, since tags are global. Move the script to the global shared area and try it again.

One clarification: runScript() in a client expression tag does have access to the “project.” namespace. All other tags can only use the “shared.” namespace. (Along with the built-in stuff.)

Good morning,
I have a analog problem

my code is this

def CheckUserRoleState(State):
retValue = False
definedRoles = system.security.getRoles()

# ciclo per tutti i ruoli da controllare passati
for role in definedRoles:
	if left(role, 2)== 'EU' and substring(role, 3,5)== 'State' 
		retValue = True
		break


return retValue

Somebody can explain me how use script function in expression for visible/enable property of object ?

Thanks

Expression tags (in the gateway) do not belong to a project, so can only call shared.* scripts.

I have try to do how suggested

runScript(“shared.Utility.CheckUserRoleState(‘DE’)”)

but nothing change…

how can find some example of how use expression with script?

Thanks

Oh, and the gateway doesn’t have a user or roles – system.security.getRoles() won’t work. That’s only meaningful at a client. If it must be a tag, it’ll have to be a client tag. And client tags can call project scripts, so you don’t need to make it shared.

Ok now script run but i have this type of error

Caused by: Traceback (most recent call last):
File “expression:runScript”, line 1, in
SyntaxError: (“mismatched input ‘\n’ expecting COLON”, (‘module:project.Utility’, 38, 60, “\t\tif left(role, 2)== ‘EU’ #and substring(role, 3,5)== State \n”))

and i have use
system.user.getRoles()

You are missing a colon from a few posts back.

# ciclo per tutti i ruoli da controllare passati
for role in definedRoles:
	if left(role, 2)== 'EU' and substring(role, 3,5)== 'State':
		retValue = True
		break


return retValue

I added it at the end of line 3

Thanks…
Question: command like left need to be declared?

Yes, you should use python slicing

Thanks :slight_smile:

I am encountering the same problem in 7.9.9

I created a shared script with a method that accepts three parameters. Two strings and a number. So something like
shared.script_a.calc_method(‘0’,‘middle’,15)
The method calculates an end date as now(), a start date as 15 seconds earlier, then calls system.tag.queryTagCalculations where the parameters are used to calculate the tag name, and Average is returned.
The last statement in the method is result.getValue(0,1) to get the float value

When I link this to a button in my project it works
When I link it to a tag using runScript(“shared.script_a.calc_method(‘0’,‘middle’,15)”), there are no errors but the result is always null.
Ultimately I want to use this in an alarm, but I can always alarm on the expression tag.

I can’t see any errors in the log. Any ideas?

Hi, I have an error in a simple runScript in expression tag, and it is located in shared scripts.
The error message doesn´t indicate too much. Attached you Will find the images.
This is in ignition 8. Any suggestions?
thank you!

I see that you are in Ignition 8 instead of the original posts which are in 7.9. There is no longer the “Global” project that you are familiar with in 7.9. Instead, tags have access to scripts that are in the Gateway Scripting Project. This is configured on the gateway web page Config > Gateway Settings > Gateway Scripting Project.
At this point, the script you want to access in the tag HAS to be on that project. Tags cannot run scripts from another project that inherits that project. From your pictures, it looks like maybe you have upgraded from 7.9 and that’s why you have a folder named “shared” which is fine, but if you upgraded from 7.9 chances are your Gateway Scripting Project is going to be Global and therefore the script has to be in the project named Global.

5 Likes

Thank you osolorzano, I followed your advice and it worked perfectly!
you are right, this Gateway was loaded from Ignition 7.9, and it created automatically the Gateway Scripting Project with the name Global.
Thank you.

Hi,
In 7.9.9, my shared script below doesn’t work in a runScript expression tag. On the contrary it works in a label component.
???

def getDbName():
	dbname=str(system.db.runQuery("SELECT DATABASE()")[0][0])
	return dbname

expression

runScript("shared.db.getDbName()")

Thanks

Tags don’t have a default database, because they aren’t in a project. You must specify the database connection name in runQuery(). See its docs.