# Running a script in expression tag

**URL:** <https://forum.inductiveautomation.com/t/running-a-script-in-expression-tag/99089>\
**Category:** Ignition\
**Tags:** perspective, scripting\
**Created:** [November 25, 2024, 6:56pm UTC](https://forum.inductiveautomation.com/t/running-a-script-in-expression-tag/99089 "2024-11-25T18:56:04Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daniella\_Donn](https://avatars.discourse-cdn.com/v4/letter/d/6a8cbe/32.png) [@Daniella\_Donn](https://forum.inductiveautomation.com/u/Daniella_Donn)\
**Post date:** [November 25, 2024, 6:56pm UTC](https://forum.inductiveautomation.com/t/running-a-script-in-expression-tag/99089/1 "2024-11-25T18:56:04Z")

</div>

Hi everyone,  
Im using an expression tag to pull some information from another memory tag dataset. I wrote a really basic script, and it does work (I tested it in the script console), however, when I go into the expression tag and write `runScript("DataFunctions.get_W_Column", 1000, "path_to_tag")`, I get an _Error\_ExpressionEval_ error and I have no idea why. Any and all help is appreciated.  
Thanks!

---

<div class="post-metadata">

**Author:** ![Daniella\_Donn](https://avatars.discourse-cdn.com/v4/letter/d/6a8cbe/32.png) [@Daniella\_Donn](https://forum.inductiveautomation.com/u/Daniella_Donn)\
**Post date:** [November 25, 2024, 6:59pm UTC](https://forum.inductiveautomation.com/t/running-a-script-in-expression-tag/99089/2 "2024-11-25T18:59:58Z")

</div>

My mistake, I also forgot to add the script I made.

```python
def get_W_Column(tag_path):
	dataset = system.tag.read(tagPath).value

    # Check if dataset is empty or null
	if dataset is None or dataset.getRowCount() == 0:
		return "Dataset is empty or null"
	
	W_column = []
	for i in range(dataset.getRowCount()):
		W_column.append(dataset.getValueAt(i, dataset.getColumnIndex("W")))
	
	return W_column

```

Thanks again!

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [November 25, 2024, 7:01pm UTC](https://forum.inductiveautomation.com/t/running-a-script-in-expression-tag/99089/3 "2024-11-25T19:01:11Z")

</div>

I’m guessing Gateway Scripting Project.  
Tags do not belong to a project, so they need to know where to look for scripts. This is done by setting a GSP on the gateway configuration page.

> [@Daniella\_Donn](#):
>
> ```python
> def get_W_Column(tag_path):
> dataset = system.tag.read(tagPath).value
> 
> # Check if dataset is empty or null
> if dataset is None or dataset.getRowCount() == 0:
> return "Dataset is empty or null"
> 	
> W_column = []
> for i in range(dataset.getRowCount()):
> W_column.append(dataset.getValueAt(i, dataset.getColumnIndex("W")))
> 	
> return W_column
> 
> ```

The only error I see is that your function takes `tag_path` as parameter, but you're passing `tagPath` to `system.tag.read`.

But you can improve a few other things here.  
`system.tag.read` is obsolete, you should be using `system.tag.readBlocking` (or `.readAsync`)

You can get a dataset column with `dataset.getColumnAsList(colu_index)` instead of building it yourself.

Also, I'd advise against returning a string when the data is null. Just return `None`, that's what it means. If you need to display a message when there's no data, do it wherever that message should be displayed, but don't store it as a value.

All in all, the script can be written like this:

```python
def get_W_Column(tag_path):
	dataset = system.tag.readBlocking(tag_path)[0].value
	if dataset is None or dataset.getRowCount() == 0:
		return None
	return dataset.getColumnAsList(dataset.getColumnIndex('W'))

```

---

<div class="post-metadata">

**Author:** ![Daniella\_Donn](https://avatars.discourse-cdn.com/v4/letter/d/6a8cbe/32.png) [@Daniella\_Donn](https://forum.inductiveautomation.com/u/Daniella_Donn)\
**Post date:** [November 25, 2024, 7:12pm UTC](https://forum.inductiveautomation.com/t/running-a-script-in-expression-tag/99089/4 "2024-11-25T19:12:47Z")

</div>

Yea....I just realized that now. Unfortunately, I cannot change the setting on the gateway configure page. I dont have the permission. Is there a way where I can take the values from a column through an expression? For example, something like..`toDataset(tag("my_tag_path")).getColumn("W")`

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [November 25, 2024, 7:14pm UTC](https://forum.inductiveautomation.com/t/running-a-script-in-expression-tag/99089/5 "2024-11-25T19:14:08Z")

</div>

Ask for whoever has the rights to that gateway to configure things properly or give you the rights to do it. It's unrealistic to expect people to work on ignition without being able to configure the gateway properly.

---

<div class="post-metadata">

**Author:** ![Daniella\_Donn](https://avatars.discourse-cdn.com/v4/letter/d/6a8cbe/32.png) [@Daniella\_Donn](https://forum.inductiveautomation.com/u/Daniella_Donn)\
**Post date:** [November 25, 2024, 7:14pm UTC](https://forum.inductiveautomation.com/t/running-a-script-in-expression-tag/99089/6 "2024-11-25T19:14:15Z")

</div>

Thanks for the helpful advice! Im still learning to use ignition so this is very helpful.

---

<div class="post-metadata">

**Author:** ![Lynn\_Martineau](https://avatars.discourse-cdn.com/v4/letter/l/f1d935/32.png) [@Lynn\_Martineau](https://forum.inductiveautomation.com/u/Lynn_Martineau)\
**Post date:** [November 25, 2024, 8:07pm UTC](https://forum.inductiveautomation.com/t/running-a-script-in-expression-tag/99089/7 "2024-11-25T20:07:01Z")

</div>

Changing the GSP shouldn't be up for grabs.  
If the configuration page is locked out, there are probably existing projects that depend on the GSP and would be broken by changing it.

Check out the possibility of: Scripting -\> Gateway Events -\> Tag Change  
That will give you control of the script as part of your project

---

<div class="post-metadata">

**Author:** ![Brandon\_Peterson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/brandon_peterson/32/32960_2.png) [@Brandon\_Peterson](https://forum.inductiveautomation.com/u/Brandon_Peterson)\
**Post date:** [November 25, 2024, 8:55pm UTC](https://forum.inductiveautomation.com/t/running-a-script-in-expression-tag/99089/8 "2024-11-25T20:55:13Z")

</div>

Hi Daniella,

What exactly are you trying to do here? It does look like you've been helped out on how to _technically_ solve your problem, but I'm guessing we have an [xy problem](https://xyproblem.info/) going on here.

It looks like you just want to get an array of values in column "W" of some dataset. You can do that right in the tag expression itself! This expression returns either a dataset with its columns rearranged, or an array of the column selected, if there was only one:

`columnRearrange({[tag_provider]path_to_tag}, 'W')`

In general, it's best practice to not do in a script (python) what can be done in an expression (built on Java). Meaning, whenever you find yourself wanting to use `runScript(...)`, double check whether you need something python-specific, or if you can instead write an expression to do the work. It's more performant, and it can make your projects easier to debug (no need to go script hunting if the logic is already in the tag).
