# Error\_expressionEval

**URL:** <https://forum.inductiveautomation.com/t/error-expressioneval/72240>\
**Category:** General Discussion\
**Tags:** scripting\
**Created:** [April 10, 2023, 4:37am UTC](https://forum.inductiveautomation.com/t/error-expressioneval/72240 "2023-04-10T04:37:24Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![fzahin](https://avatars.discourse-cdn.com/v4/letter/f/b3f665/32.png) [@fzahin](https://forum.inductiveautomation.com/u/fzahin)\
**Post date:** [April 10, 2023, 4:37am UTC](https://forum.inductiveautomation.com/t/error-expressioneval/72240/1 "2023-04-10T04:37:24Z")

</div>

I am trying to create a dataset-expression type tag that uses an expression to create its dataset. I have created a script that will return a dataset but when I am binding the value of the tag to this script using the following expression:

runScript("database.getRoleCredentials", 10, "Operator")  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/9/897ec88eab94d1fc285a39bab2898aeb352e1b2b.png)

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

I continually keep getting error\_expressionEval. I have included the script in the global project based on previous forum discussions ( [runScript in expression tag - Ignition - Inductive Automation Forum](https://forum.inductiveautomation.com/t/runscript-in-expression-tag/10378))  
and also run the script on script console. It runs fine on script console where the end product is a dataset, but I can not figure out why the expression on the dataset keeps throwing the error\_expressionEva error. Can someone please help me with this?

---

<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 10, 2023, 11:45am UTC](https://forum.inductiveautomation.com/t/error-expressioneval/72240/2 "2023-04-10T11:45:36Z")

</div>

You'll have to show your script. Also, look in the gateway logs for related errors.

You may need to use `try:` - `except:` clauses in your script to catch and log errors.

---

<div class="post-metadata">

**Author:** ![fzahin](https://avatars.discourse-cdn.com/v4/letter/f/b3f665/32.png) [@fzahin](https://forum.inductiveautomation.com/u/fzahin)\
**Post date:** [April 10, 2023, 1:11pm UTC](https://forum.inductiveautomation.com/t/error-expressioneval/72240/3 "2023-04-10T13:11:25Z")

</div>

Hi Pturmel, thanks for replying. I am pasting my script below:

```auto
logger = system.util.getLogger('customscripts.global.'+ __name__ )

def getRoleCredentials(word): 
	try:
		headers = ["Rolename", "Security Zone", "Access"]
		data = []
		usr_roles=system.tag.read("[MVNT]_dataset_users").value
		ip_addresses=system.tag.read("[MVNT]_dataset_ipadresses").value
		
		#IP ADDRESS CHECK
		
		chk1 = 0
		chk2 = 0
		logged_ip=system.tag.read("[System]Client/Network/IPAddress").value
		row_n = ip_addresses.getRowCount()
		for r in range(ip_addresses.getRowCount()):
			ip_add = ip_addresses.getValueAt(r,1)
			if (ip_add != "" and logged_ip == ip_add):
				chk1 = 1
				break
			elif (ip_add == ""):
				chk2 = chk2 +1
       
        #ROLE CHECK

		for r in range(usr_roles.getRowCount()):
			role = usr_roles.getValueAt(r,0) 
			if (role != ""):
				chk = usr_roles.getValueAt(r,1)
				if role in system.security.getRoles():
					if word in chk:
						if (chk1==1):
							data.append([role, "", "Read_Write"])
						else:
							data.append([role, "", ""])
					else:
						data.append([role, "", ""])
				else: 
					data.append([word, "", ""]) 
			else: 
				if (chk1==1):
					data.append([word, "", "Read_Write"])
				else:
					data.append([word, "", ""])
		
		sec_data = system.dataset.toDataSet(headers, data)
		return sec_data
	
	except AttributeError:
		pass

```

---

<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 10, 2023, 1:13pm UTC](https://forum.inductiveautomation.com/t/error-expressioneval/72240/4 "2023-04-10T13:13:03Z")

</div>

{ Please edit your comment, highlight all of the pasted code, then click the "preformatted text" button in the comment editor. This will make a proper code block for us, instead of the mismash currently shown. }

---

<div class="post-metadata">

**Author:** ![fzahin](https://avatars.discourse-cdn.com/v4/letter/f/b3f665/32.png) [@fzahin](https://forum.inductiveautomation.com/u/fzahin)\
**Post date:** [April 10, 2023, 1:17pm UTC](https://forum.inductiveautomation.com/t/error-expressioneval/72240/5 "2023-04-10T13:17:54Z")

</div>

Hi, I just edited my reply containing code with the correct format. Please let me know if this looks good now

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [April 10, 2023, 1:21pm UTC](https://forum.inductiveautomation.com/t/error-expressioneval/72240/6 "2023-04-10T13:21:33Z")

</div>

I don't see anything obviously wrong with your script but just check - running `getRoleCredentials("Operator")` in script console works or does it throw some error?

---

<div class="post-metadata">

**Author:** ![fzahin](https://avatars.discourse-cdn.com/v4/letter/f/b3f665/32.png) [@fzahin](https://forum.inductiveautomation.com/u/fzahin)\
**Post date:** [April 10, 2023, 1:22pm UTC](https://forum.inductiveautomation.com/t/error-expressioneval/72240/7 "2023-04-10T13:22:38Z")

</div>

it works great on the script console, returns a dataset

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [April 10, 2023, 1:31pm UTC](https://forum.inductiveautomation.com/t/error-expressioneval/72240/8 "2023-04-10T13:31:44Z")

</div>

Sanity check - is the "global" project this is defined in also configured as the Gateway Scripting Project in the gateway settings?

[https://docs.inductiveautomation.com/display/DOC81/Gateway+Settings#GatewaySettings-GatewaySettingsPropertyReference](https://docs.inductiveautomation.com/display/DOC81/Gateway+Settings#GatewaySettings-GatewaySettingsPropertyReference)

---

<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 10, 2023, 1:45pm UTC](https://forum.inductiveautomation.com/t/error-expressioneval/72240/9 "2023-04-10T13:45:02Z")

</div>

> [@fzahin](#):
>
> `logged_ip=system.tag.read("[System]Client/Network/IPAddress").value`

This is your problem. That hierarchy doesn't exist in gateway scope (nor Perspective scope). You should not expect an expression tag to be able to use any information specific to user interfaces.

---

<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 10, 2023, 1:46pm UTC](https://forum.inductiveautomation.com/t/error-expressioneval/72240/10 "2023-04-10T13:46:54Z")

</div>

Side note:

> [@fzahin](#):
>
> ```auto
> except AttributeError:
> pass
> 
> ```

This construct, if activated, guarantees you **won't** get a log entry and you **will** get a NULL returned to the tag.

---

<div class="post-metadata">

**Author:** ![fzahin](https://avatars.discourse-cdn.com/v4/letter/f/b3f665/32.png) [@fzahin](https://forum.inductiveautomation.com/u/fzahin)\
**Post date:** [April 10, 2023, 1:46pm UTC](https://forum.inductiveautomation.com/t/error-expressioneval/72240/11 "2023-04-10T13:46:58Z")

</div>

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

yeah I double checked this before based on that post

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [April 10, 2023, 1:51pm UTC](https://forum.inductiveautomation.com/t/error-expressioneval/72240/12 "2023-04-10T13:51:58Z")

</div>

Phil spotted your issue. You can't reference Vision Client tags from gateway scope.

---

<div class="post-metadata">

**Author:** ![fzahin](https://avatars.discourse-cdn.com/v4/letter/f/b3f665/32.png) [@fzahin](https://forum.inductiveautomation.com/u/fzahin)\
**Post date:** [April 10, 2023, 1:56pm UTC](https://forum.inductiveautomation.com/t/error-expressioneval/72240/13 "2023-04-10T13:56:14Z")

</div>

```auto
except AttributeError:
		test = system.tag.read("[MVNT]_dataset_users").value
		return test

```

will this edit help?

---

<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 10, 2023, 2:03pm UTC](https://forum.inductiveautomation.com/t/error-expressioneval/72240/15 "2023-04-10T14:03:51Z")

</div>

> [@fzahin](#):
>
> will this edit help?

When you catch errors in gateway scope, you should be logging the error details. Whether that is an appropriate return value is moot, as you are attempting to do something in gateway scope that is simply not possible. Gateway scope doesn't have client information.
