# Script Executing trouble

**URL:** <https://forum.inductiveautomation.com/t/script-executing-trouble/60625>\
**Category:** Ignition\
**Tags:** ignition81\
**Created:** [June 10, 2022, 4:51pm UTC](https://forum.inductiveautomation.com/t/script-executing-trouble/60625 "2022-06-10T16:51:10Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![mjohnson0238](https://avatars.discourse-cdn.com/v4/letter/m/4bbf92/32.png) [@mjohnson0238](https://forum.inductiveautomation.com/u/mjohnson0238)\
**Post date:** [June 10, 2022, 4:51pm UTC](https://forum.inductiveautomation.com/t/script-executing-trouble/60625/1 "2022-06-10T16:51:10Z")

</div>

I have a script that is supposed to zero out the doffings value at 8am but according to the power chart time recorder its not happening at that time:

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

It looks like it happens around 1AM the next day:

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

the script is executing on a boolean tag that has this as the expression:

```auto
if(dateFormat(now(), "HH:mm") = "08:05" || dateFormat(now(), "HH:mm") = "20:05", True, False)

```

The script is as follows:

```auto
opcTagPath2=[
		"[default]BitWinders/BitWinder_1/LH/dwActualNumberOfDoffings",
		"[default]BitWinders/BitWinder_1/RH/dwActualNumberOfDoffings",
		"[default]BitWinders/BitWinder_2/LH/dwActualNumberOfDoffings",
		"[default]BitWinders/BitWinder_2/RH/dwActualNumberOfDoffings"]
			
opcTagValue2 = [0] * len(opcTagPath2)

system.tag.writeBlocking(opcTagPath2,opcTagValue2)

```

It looks like everything should work, but its not. Can someone help me troubleshoot this?

---

<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:** [June 10, 2022, 5:02pm UTC](https://forum.inductiveautomation.com/t/script-executing-trouble/60625/2 "2022-06-10T17:02:37Z")

</div>

This should probably be a Gateway Scheduled Event Script.

Either way, I just learned about a better way of doing this:

> [@Browse tags printing folder](https://forum.inductiveautomation.com/t/browse-tags-printing-folder/60498/20):
>
> from com.inductiveautomation.ignition.common import TypeUtilities # Grabs current Date and Time getDateTime = system.date.now() # Returns current hour in a 0-23 format getHour = system.date.getHour24(getDateTime) # Creates list to store tag paths paths = [] # Checks if time is Midnight if getHour == 7: # Gets all tags in folder sub structure and writes to an array tags = system.tag.browseTags(parentPath="folder", recursive = True) for tag in tags: if not tag.isFolder(): …

Note that unless you have filtered the code prior to the code you shared, it will execute when the value changes, but also when the quality changes, so you probably want to insure that the value has actually made a False to True transition.

Also, verify that your Gateway, Database, and Local machine all have the same Date Time settings.

---

<div class="post-metadata">

**Author:** ![mjohnson0238](https://avatars.discourse-cdn.com/v4/letter/m/4bbf92/32.png) [@mjohnson0238](https://forum.inductiveautomation.com/u/mjohnson0238)\
**Post date:** [June 10, 2022, 5:07pm UTC](https://forum.inductiveautomation.com/t/script-executing-trouble/60625/3 "2022-06-10T17:07:08Z")

</div>

It is a Gateway script:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/5/754e2f25265cecb1c1bf9289948bfa36c7f378d9.png)

---

<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:** [June 10, 2022, 5:08pm UTC](https://forum.inductiveautomation.com/t/script-executing-trouble/60625/4 "2022-06-10T17:08:32Z")

</div>

Ah, you didn’t say that you were prior to 8.1.6.

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

---

<div class="post-metadata">

**Author:** ![mjohnson0238](https://avatars.discourse-cdn.com/v4/letter/m/4bbf92/32.png) [@mjohnson0238](https://forum.inductiveautomation.com/u/mjohnson0238)\
**Post date:** [June 10, 2022, 5:10pm UTC](https://forum.inductiveautomation.com/t/script-executing-trouble/60625/5 "2022-06-10T17:10:00Z")

</div>

My mistake sir. I am 8.1.0

---

<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:** [June 10, 2022, 5:12pm UTC](https://forum.inductiveautomation.com/t/script-executing-trouble/60625/6 "2022-06-10T17:12:01Z")

</div>

No worries, I’m sure you’ve heard it a lot, but if you can upgrade, it would definitely behoove you.

---

<div class="post-metadata">

**Author:** ![mjohnson0238](https://avatars.discourse-cdn.com/v4/letter/m/4bbf92/32.png) [@mjohnson0238](https://forum.inductiveautomation.com/u/mjohnson0238)\
**Post date:** [June 10, 2022, 5:25pm UTC](https://forum.inductiveautomation.com/t/script-executing-trouble/60625/7 "2022-06-10T17:25:14Z")

</div>

The local times look correct, here is my gateway:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/3/333c6f113502a94d9fe02dbad8359a388bbee0d8.png)

My trend chart does show its executing at 1pm and 1am.

---

<div class="post-metadata">

**Author:** ![andrews](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@andrews](https://forum.inductiveautomation.com/u/andrews)\
**Post date:** [June 10, 2022, 5:34pm UTC](https://forum.inductiveautomation.com/t/script-executing-trouble/60625/8 "2022-06-10T17:34:11Z")

</div>

Put in on a gateway timer script to check hourly with fixed rate set. Also check for time at the hourly level vs down to a minute. See the post @lrose shared.

I assume the issue with your script which checks the time and where it is located. Wherever it is located is not checking or triggering correctly. I would try that script in the script console.

---

<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:** [June 10, 2022, 5:40pm UTC](https://forum.inductiveautomation.com/t/script-executing-trouble/60625/9 "2022-06-10T17:40:57Z")

</div>

> [@andrews](#):
>
> Also try == vs = as a comparator

The first code block is the expression for the expression tag. `=` is correct in the expression language for comparisons.

I don't think the expression tag value not changing is the issue, but rather that the script is not resulting as expected.

---

<div class="post-metadata">

**Author:** ![mjohnson0238](https://avatars.discourse-cdn.com/v4/letter/m/4bbf92/32.png) [@mjohnson0238](https://forum.inductiveautomation.com/u/mjohnson0238)\
**Post date:** [June 10, 2022, 5:45pm UTC](https://forum.inductiveautomation.com/t/script-executing-trouble/60625/10 "2022-06-10T17:45:32Z")

</div>

I have changed the expression boolean tag to different time values and it becomes true between the new values. I have also put the the script in the console ant returns look correct.

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

---

<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:** [June 10, 2022, 6:00pm UTC](https://forum.inductiveautomation.com/t/script-executing-trouble/60625/11 "2022-06-10T18:00:52Z")

</div>

This sounds like a time difference issue. If you pull the historical data and manually convert the t\_stamp using the same settings that the Gateway is using, is it in the correct time?

Is the gateway for any reason in a different time zone than the database? This just feels like a time zone conversion issue.

---

<div class="post-metadata">

**Author:** ![mjohnson0238](https://avatars.discourse-cdn.com/v4/letter/m/4bbf92/32.png) [@mjohnson0238](https://forum.inductiveautomation.com/u/mjohnson0238)\
**Post date:** [June 11, 2022, 1:07am UTC](https://forum.inductiveautomation.com/t/script-executing-trouble/60625/12 "2022-06-11T01:07:48Z")

</div>

After alot of checking and double checking, I have noticed that the script is running at the time I want it to. BUT the time range on the power chart is off for whatever reason. Should I use a time series chart or something else for a more accurate time range display? Or us there some other reason that that time is off? Thanks alot for the help.
