# Tag expressions to replace Script functionality

**URL:** <https://forum.inductiveautomation.com/t/tag-expressions-to-replace-script-functionality/74421>\
**Category:** Ignition\
**Tags:** ignition81, scripting\
**Created:** [June 1, 2023, 9:11am UTC](https://forum.inductiveautomation.com/t/tag-expressions-to-replace-script-functionality/74421 "2023-06-01T09:11:26Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sam\_Bermejo](https://avatars.discourse-cdn.com/v4/letter/s/e68b1a/32.png) [@Sam\_Bermejo](https://forum.inductiveautomation.com/u/Sam_Bermejo)\
**Post date:** [June 1, 2023, 9:11am UTC](https://forum.inductiveautomation.com/t/tag-expressions-to-replace-script-functionality/74421/1 "2023-06-01T09:11:27Z")

</div>

Hi all,

I need to calculate the average value of a counter in the last 60 minutes.  
I can't use gateway scripts nor scripts in the client.

Can this be done using tags with expressions? Is this doable? What things would I need to take into account?

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

---

<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:** [June 1, 2023, 9:14am UTC](https://forum.inductiveautomation.com/t/tag-expressions-to-replace-script-functionality/74421/2 "2023-06-01T09:14:51Z")

</div>

What's the data source ? Is it a single tag with a single value, or do you have some history available ?

---

<div class="post-metadata">

**Author:** ![Sam\_Bermejo](https://avatars.discourse-cdn.com/v4/letter/s/e68b1a/32.png) [@Sam\_Bermejo](https://forum.inductiveautomation.com/u/Sam_Bermejo)\
**Post date:** [June 1, 2023, 9:19am UTC](https://forum.inductiveautomation.com/t/tag-expressions-to-replace-script-functionality/74421/3 "2023-06-01T09:19:15Z")

</div>

Hi Pascal,

No history available. Literally one OPC tag which reads the value of a counter.

I can create memory tags to store certain values (maybe use a dataset tag). But I can't use a script gateway.

Thanks

---

<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:** [June 1, 2023, 9:25am UTC](https://forum.inductiveautomation.com/t/tag-expressions-to-replace-script-functionality/74421/4 "2023-06-01T09:25:09Z")

</div>

May I ask why scripts are not an option ?

---

<div class="post-metadata">

**Author:** ![Sam\_Bermejo](https://avatars.discourse-cdn.com/v4/letter/s/e68b1a/32.png) [@Sam\_Bermejo](https://forum.inductiveautomation.com/u/Sam_Bermejo)\
**Post date:** [June 1, 2023, 9:28am UTC](https://forum.inductiveautomation.com/t/tag-expressions-to-replace-script-functionality/74421/5 "2023-06-01T09:28:16Z")

</div>

We cannot use gateway scripts as this job is for a client, and we do not have permission to access the gateway or modify anything in the gateway.

---

<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:** [June 1, 2023, 9:30am UTC](https://forum.inductiveautomation.com/t/tag-expressions-to-replace-script-functionality/74421/6 "2023-06-01T09:30:42Z")

</div>

That shouldn't prevent using scripts, though ?  
Even gateway scripts don't require you to actually access the gateway, it's all done from the designer.

Or did they specifically told you not to ?

---

<div class="post-metadata">

**Author:** ![Sam\_Bermejo](https://avatars.discourse-cdn.com/v4/letter/s/e68b1a/32.png) [@Sam\_Bermejo](https://forum.inductiveautomation.com/u/Sam_Bermejo)\
**Post date:** [June 1, 2023, 9:35am UTC](https://forum.inductiveautomation.com/t/tag-expressions-to-replace-script-functionality/74421/7 "2023-06-01T09:35:30Z")

</div>

They specifically told me I cannot use gateway scripts. That is why I'm looking for a different route to do this. I thought of using expression tags, but I don't know if this is doable. Any other options?

---

<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:** [June 1, 2023, 9:39am UTC](https://forum.inductiveautomation.com/t/tag-expressions-to-replace-script-functionality/74421/8 "2023-06-01T09:39:45Z")

</div>

That's a very weird requirement...  
It makes things convoluted and frankly quite more complex and less efficient than they should be.

I'm trying to think of a way to this cleanly...  
Can you add your counter to the historian ?

---

<div class="post-metadata">

**Author:** ![Sam\_Bermejo](https://avatars.discourse-cdn.com/v4/letter/s/e68b1a/32.png) [@Sam\_Bermejo](https://forum.inductiveautomation.com/u/Sam_Bermejo)\
**Post date:** [June 1, 2023, 9:50am UTC](https://forum.inductiveautomation.com/t/tag-expressions-to-replace-script-functionality/74421/9 "2023-06-01T09:50:23Z")

</div>

No at this stage.

---

<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:** [June 1, 2023, 9:57am UTC](https://forum.inductiveautomation.com/t/tag-expressions-to-replace-script-functionality/74421/10 "2023-06-01T09:57:05Z")

</div>

I can't think of a way to do this with built-in expression only...  
Unless maybe using `runscript` and inlining the whole thing there.

At this point, I'd rather talk with the customer and tell them they can't expect nails to be hammered down if all they allow to do it is the use of waffles.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [June 1, 2023, 10:05am UTC](https://forum.inductiveautomation.com/t/tag-expressions-to-replace-script-functionality/74421/11 "2023-06-01T10:05:51Z")

</div>

> [@Sam\_Bermejo](#):
>
> They specifically told me I cannot use gateway scripts.

> [@pascal.fragnoud](#):
>
> That's a very weird requirement...

I can see this if they're reluctant to have all of their gateway scripts in a project restart. It can be a bit disruptive.

You could add a script to the OPC tag.

---

<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:** [June 1, 2023, 10:10am UTC](https://forum.inductiveautomation.com/t/tag-expressions-to-replace-script-functionality/74421/12 "2023-06-01T10:10:06Z")

</div>

> [@JordanCClark](#):
>
> You could add a script to the OPC tag.

Can he, though ?

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [June 1, 2023, 10:14am UTC](https://forum.inductiveautomation.com/t/tag-expressions-to-replace-script-functionality/74421/13 "2023-06-01T10:14:02Z")

</div>

Depends if the customer has those tied up or not. 😉

---

<div class="post-metadata">

**Author:** ![nideyijuyidong](https://avatars.discourse-cdn.com/v4/letter/n/7cd45c/32.png) [@nideyijuyidong](https://forum.inductiveautomation.com/u/nideyijuyidong)\
**Post date:** [June 1, 2023, 10:29am UTC](https://forum.inductiveautomation.com/t/tag-expressions-to-replace-script-functionality/74421/14 "2023-06-01T10:29:29Z")

</div>

> [@pascal.fragnoud](#):
>
> That's a very weird requirement...

I did ask my colleague, not to use scripts in some places, since he is new to ignition.  
With the help of expression tags, historical value statistics can be achieved to a certain extent. For example, 12 tags store the current value at 5 minutes, 10 minutes.... respectively. Add an expression tag for averaging. This means the statistics are not very precise.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/d/8/d88e5631aad55ce1a11b50b91a7c0c9683affb44.png)

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [June 1, 2023, 10:29am UTC](https://forum.inductiveautomation.com/t/tag-expressions-to-replace-script-functionality/74421/15 "2023-06-01T10:29:34Z")

</div>

Tag valuechange event handlers aren't technically gateways scripts. Gateway scripts, by definition, are only those housed in the same named section of the project 🤷‍♂️

Edit: almost the same name... Scripting -\> Gateway events

---

<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:** [June 1, 2023, 11:34am UTC](https://forum.inductiveautomation.com/t/tag-expressions-to-replace-script-functionality/74421/16 "2023-06-01T11:34:49Z")

</div>

But they require a gateway scripting project. I kinda doubt he'll be able/allowed to put scripts on the GSP if he can't make modifications to the gateway. And even if he could, I feel like the customer would tell him not to.

---

<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:** [June 1, 2023, 12:29pm UTC](https://forum.inductiveautomation.com/t/tag-expressions-to-replace-script-functionality/74421/17 "2023-06-01T12:29:20Z")

</div>

> [@nminchin](#):
>
> Tag valuechange event handlers aren't technically gateways scripts.

Yes they are, for any ordinary scope discussion. In particular, this sounds like an Edge project without the compute plugin. In which case tag events and tag expressions involving `runScript` will all fail, and you won't be able to include your own 3rd party module to implement the desired operation.

@Sam_Bermejo: go back to the client and tell them that particular task cannot be done without scripting. Full stop.
