# Expression Tag - Error\_ExpressionEval

**URL:** <https://forum.inductiveautomation.com/t/expression-tag-error-expressioneval/87668>\
**Category:** Ignition\
**Tags:** ignition81, perspective, scripting\
**Created:** [March 20, 2024, 11:07pm UTC](https://forum.inductiveautomation.com/t/expression-tag-error-expressioneval/87668 "2024-03-20T23:07:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sameer\_Ambegaonkar](https://avatars.discourse-cdn.com/v4/letter/s/41988e/32.png) [@Sameer\_Ambegaonkar](https://forum.inductiveautomation.com/u/Sameer_Ambegaonkar)\
**Post date:** [March 20, 2024, 11:07pm UTC](https://forum.inductiveautomation.com/t/expression-tag-error-expressioneval/87668/1 "2024-03-20T23:07:05Z")

</div>

I have the script with throw a error\_expressioneval. Runs fine in the script console.  
Not sure where is the script error. Attached screenshot of expression tag.

def GenPE():

```
# Define variables
path1 = 'xx/ATS-01-PR-A/POS'
path2 = 'xx/MPE'
path3 = 'xx/MPE_Previous'
path4 = 'xx/PE'
path5 = 'xx/RUN'
tag1 = system.tag.readBlocking(path1)
tag2 = system.tag.readBlocking(path2)
tag3 = system.tag.readBlocking(path3)
tag4 = system.tag.readBlocking(path4)
tag5 = system.tag.readBlocking(path5)
atspos=tag1[0]
mpe=tag2[0]
mpe_prev=tag3[0]
gpe=tag4[0]
run=tag5[0]
pediff=0
if atspos.value==2 and run.value==0:
	pediff = mpe.value - mpe_prev.value
	gpe.value = pediff + gpe.value
	system.tag.writeBlocking(path4, gpe)
system.tag.writeBlocking(path3, mpe)
return gpe.value

```

![energy](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/1/31bbf4e281389312eb05791118a6edacce94d638.png)  
 ![energy1](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/e/8ee87ab47f0236f27d646b67911d776099c61751.png)

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [March 21, 2024, 12:58am UTC](https://forum.inductiveautomation.com/t/expression-tag-error-expressioneval/87668/2 "2024-03-21T00:58:33Z")

</div>

I can't see the problem (yet) but here are a few tips:

1. See [Wiki - how to post code on this forum](https://forum.inductiveautomation.com/t/wiki-how-to-post-code-on-this-forum/77831). Yours is almost OK except for the first line.
2. `system.tag.readBlocking()` expects a **list** of tag paths so even when there is only one it should be in `[]` brackets.
3. Since `system.tag.readBlocking` can handle a list you do them all at once.

```auto
    tagPaths = ['xx/ATS-01-PR-A/POS',
                'xx/MPE',
                'xx/MPE_Previous',
                'xx/PE'.
                'xx/RUN'
    ]
    tagValues = system.tag.readBlocking(tagPaths)

```

Your code would then need to reference tagValues[0], etc.

1. You also need `[]` lists on the writeBlocking line.  
`system.tag.writeBlocking([tagPaths[2]], [mpe])`

In current Ignition version the functions work when only one parameter is supplied (not in a list) but it's undocumented and could be "fixed" in the future.

* * *

A further thought - and this might be the problem: The script needs to be on the gateway, not in your project, otherwise the tag event can't find it. Where have you stored the script?

> **[Gateway Event Scripts | Ignition User Manual](https://docs.inductiveautomation.com/docs/8.1/platform/scripting/scripting-in-ignition/gateway-event-scripts#tag-change-scripts)**
>
> Gateway Event Scripts Overview

---

<div class="post-metadata">

**Author:** ![amy.sudibyo](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amy.sudibyo/32/38659_2.png) [@amy.sudibyo](https://forum.inductiveautomation.com/u/amy.sudibyo)\
**Post date:** [March 21, 2024, 1:54am UTC](https://forum.inductiveautomation.com/t/expression-tag-error-expressioneval/87668/3 "2024-03-21T01:54:05Z")

</div>

I also don't see why this calculation needs to be in a script. Why not perform the calculation directly in the expression on the expression tag? Seems that all the input tags have the same base path which could be parameterised.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [March 21, 2024, 11:21am UTC](https://forum.inductiveautomation.com/t/expression-tag-error-expressioneval/87668/4 "2024-03-21T11:21:30Z")

</div>

> [@Transistor](#):
>
> `system.tag.readBlocking()` expects a **list** of tag paths so even when there is only one it should be in `[]` brackets.

It will accept a single string as well. It still returns a list though.

Your point #3 is valid however and is definitely the way the script should be written.

---

<div class="post-metadata">

**Author:** ![Sameer\_Ambegaonkar](https://avatars.discourse-cdn.com/v4/letter/s/41988e/32.png) [@Sameer\_Ambegaonkar](https://forum.inductiveautomation.com/u/Sameer_Ambegaonkar)\
**Post date:** [March 22, 2024, 2:03am UTC](https://forum.inductiveautomation.com/t/expression-tag-error-expressioneval/87668/5 "2024-03-22T02:03:33Z")

</div>

Thanks for the reply. Implemented with script configured as a scheduled gateway event.
