# Record and Reset the tag values every hour via transaction group

**URL:** <https://forum.inductiveautomation.com/t/record-and-reset-the-tag-values-every-hour-via-transaction-group/91117>\
**Category:** Ignition\
**Tags:** scripting\
**Created:** [May 30, 2024, 6:14am UTC](https://forum.inductiveautomation.com/t/record-and-reset-the-tag-values-every-hour-via-transaction-group/91117 "2024-05-30T06:14:10Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dharani\_T](https://avatars.discourse-cdn.com/v4/letter/d/bc8723/32.png) [@Dharani\_T](https://forum.inductiveautomation.com/u/Dharani_T)\
**Post date:** [May 30, 2024, 6:14am UTC](https://forum.inductiveautomation.com/t/record-and-reset-the-tag-values-every-hour-via-transaction-group/91117/1 "2024-05-30T06:14:10Z")

</div>

Hi team,

I need to record a list of tags every hour at times like 1:30, 2:30, 3:30, etc. During a shift, there will be 8 records.

For example:

- `Tag`: `ProductionStartDateTime` - 30-05-2024 11:30 (expression tag)
- `ProductionEndDateTime` - current time

I want to record the tag values via a transaction group and then reset the tag. The trigger for this transaction is a boolean tag, which will be enabled when the time crosses every hour, e.g., 30-05-2024 12:30.

Initially, I set the expression tag as follows

```python
if ({[~]Global Tags/Current Minute} = 30 && {[~]Global Tags/Current Second} = 0, 1, 0)

```

However, some recorded tag values were null because they were reset after the hour. I then modified the expression to:

```python
if ({[~]Global Tags/Current Minute} = 29 && {[~]Global Tags/Current Second} > 50, 1, 0)

```

But the same issue occurred. Finally, I changed it to:

```python
if ({[~]Global Tags/Current Minute} = 29 && {[~]Global Tags/Current Second} > 45, 1, 0)

```

This worked fine, but the recorded times are not exactly one hour apart. For example:

- `ProductionStartDateTime` - 30-05-2024 11:30:00
- `ProductionEndDateTime` - 30-05-2024 12:29:47

The runtime is not exactly one hour, and when I check the total runtime for the shift, it is 478 minutes instead of 480 minutes because of this issue.

Any ideas on how to overcome this?

---

<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:** [May 30, 2024, 8:08am UTC](https://forum.inductiveautomation.com/t/record-and-reset-the-tag-values-every-hour-via-transaction-group/91117/2 "2024-05-30T08:08:06Z")

</div>

This sounds like a job for a [Gateway Event Script](https://docs.inductiveautomation.com/docs/8.1/platform/scripting/scripting-in-ignition/gateway-event-scripts#gateway-scheduled-scripts).  
Set it up for `(30 * * * *)` to have a script run at half-past the hour.

The real problem is that you have created a race condition. If you are recording process or machine counters then I would recommend never resetting them and recording ever-increasing numbers. It makes it very easy to calculate the difference in value between any two timestamps and also gives you some protection against loss of data if a value is missed for some reason (Ignition offline, network error, etc.).

If you _must_ reset the values then do it in the same script that reads the tags and use `system.tag.readBlocking` to ensure that you've captured the values before writing the reset value out.

---

<div class="post-metadata">

**Author:** ![Dharani\_T](https://avatars.discourse-cdn.com/v4/letter/d/bc8723/32.png) [@Dharani\_T](https://forum.inductiveautomation.com/u/Dharani_T)\
**Post date:** [May 30, 2024, 8:32am UTC](https://forum.inductiveautomation.com/t/record-and-reset-the-tag-values-every-hour-via-transaction-group/91117/3 "2024-05-30T08:32:53Z")

</div>

Thanks for the suggestion, but how to configure to get exactly at 1:30:00  
i tried but got the data at 1:29:57. i think there's no way tp configure custom second in scheduled event

Edited:

I got the root cause of this issue,

My recorded time is exactly 1:30:00  
but my ProductionEndTime: 1:29:57  
its an expression tag

```python
dateFormat({[~]Global Tags/Current Time}, "yyyy-MM-dd HH:mm:ss")

```

note: /Current Time is changing every second but ProductionEndTime executes every 8 second even if i put it as fixed rate

---

<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:** [May 30, 2024, 12:01pm UTC](https://forum.inductiveautomation.com/t/record-and-reset-the-tag-values-every-hour-via-transaction-group/91117/4 "2024-05-30T12:01:49Z")

</div>

The gateway event will trigger at xx:30:00.

Yes, your system is fragile and will break from time to time. You need to run things in sequence - not on time values. I suggest a redesign.

---

<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:** [May 30, 2024, 4:58pm UTC](https://forum.inductiveautomation.com/t/record-and-reset-the-tag-values-every-hour-via-transaction-group/91117/5 "2024-05-30T16:58:39Z")

</div>

I wouldn't reset the value (except, perhaps at the start of shift). Keep it as an odometer-style value and log the difference from the previous hour.

Better yet, just log the odometer value and use the database to calculate the values.
