# runScript in expression tag

**URL:** <https://forum.inductiveautomation.com/t/runscript-in-expression-tag/10378>\
**Category:** Ignition\
**Created:** [August 21, 2015, 2:06pm UTC](https://forum.inductiveautomation.com/t/runscript-in-expression-tag/10378 "2015-08-21T14:06:09Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![andrea.montresor](https://avatars.discourse-cdn.com/v4/letter/a/5f9b8f/32.png) [@andrea.montresor](https://forum.inductiveautomation.com/u/andrea.montresor)\
**Post date:** [August 21, 2015, 2:06pm UTC](https://forum.inductiveautomation.com/t/runscript-in-expression-tag/10378/1 "2015-08-21T14:06:09Z")

</div>

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

 ![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/8/8dc68dd43d9107c0f4cb7185e947eb8789d2445c.png)

---

<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:** [August 21, 2015, 2:26pm UTC](https://forum.inductiveautomation.com/t/runscript-in-expression-tag/10378/2 "2015-08-21T14:26:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Duffanator](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/duffanator/32/3560_2.png) [@Duffanator](https://forum.inductiveautomation.com/u/Duffanator)\
**Post date:** [August 21, 2015, 2:34pm UTC](https://forum.inductiveautomation.com/t/runscript-in-expression-tag/10378/3 "2015-08-21T14:34:09Z")

</div>

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.

---

<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:** [August 21, 2015, 3:04pm UTC](https://forum.inductiveautomation.com/t/runscript-in-expression-tag/10378/4 "2015-08-21T15:04:27Z")

</div>

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.)

---

<div class="post-metadata">

**Author:** ![SergioS](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@SergioS](https://forum.inductiveautomation.com/u/SergioS)\
**Post date:** [April 26, 2018, 7:22am UTC](https://forum.inductiveautomation.com/t/runscript-in-expression-tag/10378/5 "2018-04-26T07:22:31Z")

</div>

Good morning,  
I have a analog problem

 ![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/d/d255e62677ed995233bac72612c256713bba9f72.png)

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

---

<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:** [April 26, 2018, 11:36am UTC](https://forum.inductiveautomation.com/t/runscript-in-expression-tag/10378/6 "2018-04-26T11:36:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![SergioS](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@SergioS](https://forum.inductiveautomation.com/u/SergioS)\
**Post date:** [April 26, 2018, 7:41pm UTC](https://forum.inductiveautomation.com/t/runscript-in-expression-tag/10378/7 "2018-04-26T19:41:55Z")

</div>

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

---

<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:** [April 26, 2018, 7:53pm UTC](https://forum.inductiveautomation.com/t/runscript-in-expression-tag/10378/8 "2018-04-26T19:53:44Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![SergioS](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@SergioS](https://forum.inductiveautomation.com/u/SergioS)\
**Post date:** [April 26, 2018, 8:17pm UTC](https://forum.inductiveautomation.com/t/runscript-in-expression-tag/10378/9 "2018-04-26T20:17:08Z")

</div>

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”))

---

<div class="post-metadata">

**Author:** ![SergioS](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@SergioS](https://forum.inductiveautomation.com/u/SergioS)\
**Post date:** [April 26, 2018, 8:18pm UTC](https://forum.inductiveautomation.com/t/runscript-in-expression-tag/10378/10 "2018-04-26T20:18:09Z")

</div>

and i have use  
system.user.getRoles()

---

<div class="post-metadata">

**Author:** ![ethomason](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ethomason/32/43338_2.png) [@ethomason](https://forum.inductiveautomation.com/u/ethomason)\
**Post date:** [April 26, 2018, 8:46pm UTC](https://forum.inductiveautomation.com/t/runscript-in-expression-tag/10378/11 "2018-04-26T20:46:58Z")

</div>

You are missing a colon from a few posts back.

```auto
# 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

---

<div class="post-metadata">

**Author:** ![SergioS](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@SergioS](https://forum.inductiveautomation.com/u/SergioS)\
**Post date:** [April 26, 2018, 8:58pm UTC](https://forum.inductiveautomation.com/t/runscript-in-expression-tag/10378/12 "2018-04-26T20:58:44Z")

</div>

> [@ethomason](#):
>
> left

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

---

<div class="post-metadata">

**Author:** ![ethomason](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ethomason/32/43338_2.png) [@ethomason](https://forum.inductiveautomation.com/u/ethomason)\
**Post date:** [April 26, 2018, 9:43pm UTC](https://forum.inductiveautomation.com/t/runscript-in-expression-tag/10378/13 "2018-04-26T21:43:02Z")

</div>

Yes, [you should use python slicing](https://stackoverflow.com/questions/22586286/python-is-there-an-equivalent-of-mid-right-and-left-from-basic)

---

<div class="post-metadata">

**Author:** ![SergioS](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@SergioS](https://forum.inductiveautomation.com/u/SergioS)\
**Post date:** [April 27, 2018, 7:03am UTC](https://forum.inductiveautomation.com/t/runscript-in-expression-tag/10378/14 "2018-04-27T07:03:31Z")

</div>

Thanks 🙂

---

<div class="post-metadata">

**Author:** ![mtoback](https://avatars.discourse-cdn.com/v4/letter/m/3bc359/32.png) [@mtoback](https://forum.inductiveautomation.com/u/mtoback)\
**Post date:** [August 14, 2019, 9:03pm UTC](https://forum.inductiveautomation.com/t/runscript-in-expression-tag/10378/15 "2019-08-14T21:03:05Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![cristhian.rey](https://avatars.discourse-cdn.com/v4/letter/c/0ea827/32.png) [@cristhian.rey](https://forum.inductiveautomation.com/u/cristhian.rey)\
**Post date:** [September 17, 2019, 10:49pm UTC](https://forum.inductiveautomation.com/t/runscript-in-expression-tag/10378/16 "2019-09-17T22:49:10Z")

</div>

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!

 ![Test%20Function](https://us1.discourse-cdn.com/inductiveautomation/original/2X/2/2d62b4dce09177600764b69212bd380e4fd27abb.png) ![Test%20Function%202](https://us1.discourse-cdn.com/inductiveautomation/original/2X/b/b5ecac6af7b49db7b498ab3e967d6ca3c6ec16bb.png) ![Test%20Function%20error](https://us1.discourse-cdn.com/inductiveautomation/original/2X/6/63333a7b338032cb01add1d38196a24615881a09.png)

---

<div class="post-metadata">

**Author:** ![osolorzano](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/osolorzano/32/6432_2.png) [@osolorzano](https://forum.inductiveautomation.com/u/osolorzano)\
**Post date:** [September 18, 2019, 12:08am UTC](https://forum.inductiveautomation.com/t/runscript-in-expression-tag/10378/17 "2019-09-18T00:08:42Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![cristhian.rey](https://avatars.discourse-cdn.com/v4/letter/c/0ea827/32.png) [@cristhian.rey](https://forum.inductiveautomation.com/u/cristhian.rey)\
**Post date:** [September 18, 2019, 4:37pm UTC](https://forum.inductiveautomation.com/t/runscript-in-expression-tag/10378/18 "2019-09-18T16:37:25Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![flavien](https://avatars.discourse-cdn.com/v4/letter/f/f475e1/32.png) [@flavien](https://forum.inductiveautomation.com/u/flavien)\
**Post date:** [October 9, 2019, 10:16am UTC](https://forum.inductiveautomation.com/t/runscript-in-expression-tag/10378/19 "2019-10-09T10:16:17Z")

</div>

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.  
???

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

```

expression

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

```

Thanks

---

<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:** [October 9, 2019, 11:16am UTC](https://forum.inductiveautomation.com/t/runscript-in-expression-tag/10378/20 "2019-10-09T11:16:44Z")

</div>

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.

[Next page](https://forum.inductiveautomation.com/t/runscript-in-expression-tag/10378.md?page=2)
