# Gateway Tag Event Script - Event Driven Bug?

**URL:** <https://forum.inductiveautomation.com/t/gateway-tag-event-script-event-driven-bug/98637>\
**Category:** Ignition\
**Created:** [November 14, 2024, 8:59pm UTC](https://forum.inductiveautomation.com/t/gateway-tag-event-script-event-driven-bug/98637 "2024-11-14T20:59:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kyler.kamyszek](https://avatars.discourse-cdn.com/v4/letter/k/a4c791/32.png) [@kyler.kamyszek](https://forum.inductiveautomation.com/u/kyler.kamyszek)\
**Post date:** [November 14, 2024, 8:59pm UTC](https://forum.inductiveautomation.com/t/gateway-tag-event-script-event-driven-bug/98637/1 "2024-11-14T20:59:52Z")

</div>

Am I missing something? I had the following expression that was working with Fixed Rate execution mode and in the gateway tag change script.

```python
if({[.]inDeviation} = True && {[.]../../shift/secondsInShift} >2,dateDiff({[.]prevCountTimestamp},{[System]Gateway/CurrentDateTime},"second") - {[.]deviationCycleTime.value},0)

```

Then I switched to event and the gateway script only triggered on the inDeviation change.

```python
if({[.]inDeviation} = True && {[.]../../shift/secondsInShift} >2,dateDiff({[.]prevCountTimestamp},now(1000),"second") - {[.]deviationCycleTime.value},0)

```

My gateway script then doesn't capture the change of the tag on the now() function in the expression. The tag value changes as expected.

---

<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:** [November 14, 2024, 9:47pm UTC](https://forum.inductiveautomation.com/t/gateway-tag-event-script-event-driven-bug/98637/2 "2024-11-14T21:47:53Z")

</div>

It doesn't say it in [now | Ignition User Manual](https://www.docs.inductiveautomation.com/docs/8.1/appendix/expression-functions/date-and-time/now), but I imagine this will work in Vision and Perspective expressions but not in tags. I imagine that this is because of the way that things get added to a watch events or schedules.

* * *

Comments:

- You don't need `== True` when testing a boolean. The boolean will return a True or False.
- Expressions can take line breaks, spaces and tabs to improve legibility.
- Add a space after a comma and before and after operators (=, \<, \>, etc.), as done in written English. It makes reading much easier and will allow text wrapping on space in some editors.

```python
if(
    {[.]inDeviation} 
    && {[.]../../shift/secondsInShift} > 2,
    dateDiff(
        {[.]prevCountTimestamp}, 
        {[System]Gateway/CurrentDateTime},
        "second"
    ) - {[.]deviationCycleTime.value},
    0
)

```

```python
if(
    {[.]inDeviation} 
    && {[.]../../shift/secondsInShift} > 2,
    dateDiff({[.]prevCountTimestamp}, now(1000), "second") 
      - {[.]deviationCycleTime.value},
    0
)

```

---

<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:** [November 14, 2024, 10:17pm UTC](https://forum.inductiveautomation.com/t/gateway-tag-event-script-event-driven-bug/98637/3 "2024-11-14T22:17:00Z")

</div>

The `now()` expression function ignores its argument when used in an expression tag, and that tag is **not** in event driven mode. (Same for `runScript()`.)

If you are using `now()` or `runScript()` in expression tags, you probably **do** want event driven mode.
