# When does the valueChanged script run

**URL:** <https://forum.inductiveautomation.com/t/when-does-the-valuechanged-script-run/17301>\
**Category:** Ignition\
**Created:** [March 9, 2018, 7:31pm UTC](https://forum.inductiveautomation.com/t/when-does-the-valuechanged-script-run/17301 "2018-03-09T19:31:33Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![codersmurf](https://avatars.discourse-cdn.com/v4/letter/c/df788c/32.png) [@codersmurf](https://forum.inductiveautomation.com/u/codersmurf)\
**Post date:** [March 9, 2018, 7:31pm UTC](https://forum.inductiveautomation.com/t/when-does-the-valuechanged-script-run/17301/1 "2018-03-09T19:31:33Z")

</div>

I have a bunch of coils, each coil calls a shared script that turns the coil bools into strings and converts them to a number to bitwise compare with a magic number to see if a fault has happened. When testing the machine will set the coil that updates the tag, but the script never runs. I tried putting in a print statement in the script to chech on the server and nothing ever shows up, any thoughts? Thanks

---

<div class="post-metadata">

**Author:** ![bfuson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bfuson/32/4597_2.png) [@bfuson](https://forum.inductiveautomation.com/u/bfuson)\
**Post date:** [March 9, 2018, 7:33pm UTC](https://forum.inductiveautomation.com/t/when-does-the-valuechanged-script-run/17301/2 "2018-03-09T19:33:22Z")

</div>

Are you using a ValueChange event script for firing your shared script? Can you post it?

---

<div class="post-metadata">

**Author:** ![codersmurf](https://avatars.discourse-cdn.com/v4/letter/c/df788c/32.png) [@codersmurf](https://forum.inductiveautomation.com/u/codersmurf)\
**Post date:** [March 9, 2018, 7:39pm UTC](https://forum.inductiveautomation.com/t/when-does-the-valuechanged-script-run/17301/3 "2018-03-09T19:39:59Z")

</div>

Here’s the shared script:

import re

def Faulted(tag):  
tag = re.sub("([).\*?(])", “\g\<1\>\g\<2\>”, tag)  
unit = tag[:tag.index("/")]  
path=[]  
for fault in range(1,69):  
path.append(unit + ‘/Faults/Fault’ + str(fault))  
values = system.tag.readAll(path)  
lfaults = map(lambda x: str(int(x.value == True)), values)  
faults = ‘’.join(lfaults)  
raw1 = int(faults[:31], 2)  
raw2 = int(faults[32:63], 2)  
raw3 = int(faults[64:67], 2)  
val = False  
print “jake0”  
print "jake1: ", faults[:31], faults[32:63], faults[64:67]  
if raw1 & 3271557119 or raw2 & 4110413567 or raw3 & 14:  
val = True  
system.tag.write(unit + ‘/Faulted’, val)import re

Here’s the value changed script:

shared.Master.Faulted(tagPath)

Thanks

---

<div class="post-metadata">

**Author:** ![bfuson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bfuson/32/4597_2.png) [@bfuson](https://forum.inductiveautomation.com/u/bfuson)\
**Post date:** [March 9, 2018, 8:09pm UTC](https://forum.inductiveautomation.com/t/when-does-the-valuechanged-script-run/17301/4 "2018-03-09T20:09:14Z")

</div>

For debugging this, you’re correct in checking the Gateway since Tag Change Events occur there. Try using a logger instead of print statements though, something like this:

`system.util.getLogger("TagChange").info("Your_debug_message")`

You can add unique messages in both the shared script and the tag event script.

---

<div class="post-metadata">

**Author:** ![codersmurf](https://avatars.discourse-cdn.com/v4/letter/c/df788c/32.png) [@codersmurf](https://forum.inductiveautomation.com/u/codersmurf)\
**Post date:** [March 9, 2018, 9:25pm UTC](https://forum.inductiveautomation.com/t/when-does-the-valuechanged-script-run/17301/5 "2018-03-09T21:25:25Z")

</div>

So I get messages sometimes and not others, it’s very erratic.

---

<div class="post-metadata">

**Author:** ![codersmurf](https://avatars.discourse-cdn.com/v4/letter/c/df788c/32.png) [@codersmurf](https://forum.inductiveautomation.com/u/codersmurf)\
**Post date:** [March 13, 2018, 1:11am UTC](https://forum.inductiveautomation.com/t/when-does-the-valuechanged-script-run/17301/6 "2018-03-13T01:11:43Z")

</div>

So this thing is kicking my ass, I can’t get the valueChanged event to trigger unless I disable and reenable a tag, is this a bug, or is there something I’m missing? I have a folder with a bunch of bools in it. The bools are opc tags getting data from coils. They run a script that will update a historical memory tag on the udt that the bools are on. Thanks
