# UDT failing to execute

**URL:** <https://forum.inductiveautomation.com/t/udt-failing-to-execute/53440>\
**Category:** Ignition\
**Created:** [November 24, 2021, 4:48pm UTC](https://forum.inductiveautomation.com/t/udt-failing-to-execute/53440 "2021-11-24T16:48:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nicholas.robinson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nicholas.robinson/32/22188_2.png) [@nicholas.robinson](https://forum.inductiveautomation.com/u/nicholas.robinson)\
**Post date:** [November 24, 2021, 4:48pm UTC](https://forum.inductiveautomation.com/t/udt-failing-to-execute/53440/1 "2021-11-24T16:48:51Z")

</div>

Below is a simple version of the actual UDT, but the functionality is:

1. During a period of time, count on certain conditions (check once per second)
2. On the hour clock the results into a dataset and reset the count to 0

What I am observing is that the part of archiving the data and zeroing out the value happens only sometimes but other times it never occurs. So if the maximum seconds in an hour is 3600, I start to see values going to 5000 etc. because the reset is not happening.

What could be causing part of the code never to execute of execute only sometimes?

The trigger is just a second counter:

```auto
getSecond(now())

```

Which activates this tag change script

```auto
def valueChanged(tag, tagPath, previousValue, currentValue, initialChange, missedEvents):

	count = system.tag.read("[.]value").value
	updatedCount = count + 1
	system.tag.write("[.]value", updatedCount)
	
	if currentValue.value == 0 and system.date.getMinute(system.date.now()) == 0:
		history = system.tag.read("[.]history").value
		history = system.dataset.addRow(
			history,
			[system.date.now(), updatedCount]
		)
		system.tag.writeBlocking(
			["[.]history", "[.]value"],
			[history, 0]
		)

```

The UDT structure is like this:

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/4/e49a2e29b4f858a007bcaf72f7d93f1b5240d7a8.png)

Thanks,

Nick

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [November 25, 2021, 12:24am UTC](https://forum.inductiveautomation.com/t/udt-failing-to-execute/53440/2 "2021-11-25T00:24:28Z")

</div>

Add some logging to the script execution that includes the value of the missedEvents flag. Maybe that’s happening.

Oh, also, it looks like you’re checking `currentValue.value == 0` and optimistically assuming that your system never pauses for GC or something else that causes you not to catch the 0 second. Also something logging will hopefully expose.

---

<div class="post-metadata">

**Author:** ![nicholas.robinson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nicholas.robinson/32/22188_2.png) [@nicholas.robinson](https://forum.inductiveautomation.com/u/nicholas.robinson)\
**Post date:** [December 3, 2021, 3:00pm UTC](https://forum.inductiveautomation.com/t/udt-failing-to-execute/53440/3 "2021-12-03T15:00:32Z")

</div>

at the end of the day, it seems we had too much trying to execute at the same time. This was fixed by having the execution take place at a different second of the minute.

Thanks,

Nick
