Tag Change Script


We have a number of points to monitor status of our CRAC units. One of these points tells us the supply temperature, and another tells us whether the unit is running or not.

I created a “Tag Change” script so that whenever the unit turns off (and therefore, the tag state changes), code is executed to put the supply temperature point into what we call “maintenance mode”. Maintenance mode basically just sets the “intval” column in sqlt_meta to 0 for a name of ‘alertmode’. This disables the alarm on a SQLTag, while retaining all of the configuration information. When the unit turns back on, we re-enable the alert by setting this ‘intval’ column back to a 2 for analog alert.

Everything seems to be working well, but I’ve come across a minor issue where this script will be run on startup of Ignition. Now, this is expected as the documentation says this will happen when the scripting system initially starts up, but I end up with a bunch of entries in my audit log for all of the scripts running. Is there any sort of variable that I can check to see if the script is firing due to the scripting system starting (similar to the initialChange variable when the tag is first subscribed)?

Thank you!

Yes. The tag change scripts have a special variable called initialChange that is a boolean. The intialChange variable is a flag (0 or 1) that indicates whether or not this event is due to initially subscribing or not. You can filter it out:[code]if not initialChange:

do your code[/code]Here is the page in the manual that talks about tag change scripts:

inductiveautomation.com/supp … cripts.htm

1 Like

Interesting… Currently what I have is:

#Make sure this isn't running due to the tag being created/gateway starting
if 0 == initialChange:
	#... Code here

Shouldn’t that work the same way? Am I overlooking something?

That should work. What is happening? Maybe you should print out initialChange and see what it is in the wrapper.log on the server.

We recently installed version 7.5.5 to fix the 7.5.4 problem and the tag change enable flag problem.
Now I’m having a problem with “initializing” my tag change scripts. I am logging (to the gateway log) an event message with the value of initialChange. Then the script has a “if initialChange==0:” to control execution of the rest of the script. When I “Save and Publish”, it appears to skip the 1st script (as sorted in the script editor) as evidenced in the log file with an initialChange value of 1. If I rename the script (and see the sort order change) then “S&P”, the new 1st item appears to be skipped and the renamed item is logged with an initialchange value of 1.

Is anyone else experiencing this problem?

I’m a little unclear on the problem, perhaps because it’s the nearing the end of the day here. :scratch: Initial tests I did with the initialChange value seem to show that it’s working ok, but my setup is probably different than yours.

So you have two tag change scripts, one prints the initialChange value, and the other starts with the initialChange condition statement? When you say the 1st scripts were skipped, what are the contents of those scripts? Are the scripts monitoring the same tag, or different tags? Save & Publish will reload the gateway scripts, which will establish a new subscription on first change, hence the initialChange value being 1 after the save.

To clarify:
I have 4 tag change scripts(gateway scripts).

Each starts with>>>>>>>>>>>>
import system
import app

cmtstr = “{script name} (%d)”%initialChange

if initialChange ==0:
some more script statements.

app.lprint is an Inductive Automation example to log data to the Gateway console log (visible in the browser).

To start, I have a list of tag change script names:
On Change getOperCmts
On Change CureCycleNumber
On Change MachineRunning
On Change RecipeStepChange

When I “save and Publish” the project, I see entries for scripts 2,3,& 4 with an initialChange value of 1. All, well and good except for the missing entry for the 1st script.
I change the name of the 1st script to On Change_getOperCmts to put it at the bottom of the list.
On Change CureCycleNumber
On Change MachineRunning
On Change RecipeStepChange
On Change_getOperCmts

Then I “save and publish” again. This time, the entry for On Change CureCycleNumber is missing from the Gateway console log. I’ve also tested this with other name variations, On Change getOperComments; for example. For the time being, I’m using a minimal script named On Change AAAA, that triggers off of a simple SQLtag, a memory tag of int type to act as a counter.

As a note: this is an SQLBridge Gateway project, not an HMI client and no windows. Its purpose is to collect data when a Steel curing oven runs a batch of part and it interacts with the CompactLogix controller tags to read/write tags shared with the RSView HMI on an existing oven. We are new to Ignition and use it to replace a csv file for collecting data with the SQLBridge writing directly(realtime) to an Oracle Db.

My replication of the issue so far has been hit or miss, each script is referencing a different tag, right? Also, do you mind attaching the lprint() script? Maybe something is going on in there as well.

Yes, I can. I could send a text file with the entire scripts. I would prefer to email the file rather than a long post in the forum.

def lprint(message):
import system
log = system.util.logger(“HTlogger”)

You can either PM me the scripts, or you can send them in to support@inductiveautomation.com.

Has there been any solution for this?

I think am experiencing the same problem:
When the scripts are restarted (due to a save after a script change) there is no initial execution.
Some time later, when the value changes, the script is executed with ‘initialChange’ = 1.

According to the manual i would expect an initial execution after a restart with ‘initialChange’=1 and all later executions caused by value changes with ‘initialChange’ = 0.
Currently i always miss one change event when the scripts are restartet. If i could be sure that there will never be an initial execution, i would simply remove the initialChange check.

I was able to confirm this was a bug, and it has been added to our bug ticket system. When it is fixed, this thread will be updated.

Another curiosity, I added a 2nd tag to two of my Tag Change scripts. Now, the scripts initialize correctly; i.e., those with 2 trigger tags update twice and the others update for their single tags.
Just FYI if it is need for troubleshooting.

Does anyone know if this has been fixed?

Is anyone still experiencing this issue with the latest versions (7.6.4 or 7.5.11)?