Power of Ignition Tag Event Scripting: Automating Runtime, Calculations, and Database Updates

May 18, 2023  •  by Abraham Ouma

Tag event scripting in Ignition is one of the most powerful tools I’ve relied on throughout many of my projects, especially when tracking the operation of machine components whose tags are bound from PLCs or other field devices. The ability to respond to changes in tag values in real-time has enabled me to implement custom logic without needing external systems or tools. Here are some of the areas where I’ve explored and heavily utilized tag event scripting:

  • Tracking the runtime of components
  • Performing mathematical calculations such as integration at the end of a component’s running cycle - I’ll explain this in detail.
  • Updating database records in real time

Application of Tag Event Change Scripts in Tracking Runtime

Let’s say you want to track how long a component has been running or idle and store that duration in a memory tag. You can use a tag event script in combination with a gateway script to keep track of the component's operation time.

For example, suppose we’re using Ignition to monitor and control a boiler that’s connected to an S7-1200 PLC. We can write a tag change script on the boiler’s status tag to detect when it switches from ON to OFF, or vice versa, and trigger a gateway timer script that tracks runtime.

Example Setup:

  • OPC Tag: [default]Boiler (monitors boiler status)
  • Memory Tag: [default]Boiler_uptime (stores uptime count in minutes)

The gateway script runs every minute. If the boiler is ON during that check, the script increments the Boiler_uptime tag by 1. This gives you a cumulative count of the total minutes the boiler has been running.

Gateway timer script

Why This Method Works for Me:

If I’m only tracking a handful of components, I prefer this method over using the transaction group’s event meter, which I’ve found to be a bit unreliable in some setups. Yes, because the script runs every minute, there may be a slight offset of a few seconds, but for most use cases, that’s acceptable. If you need higher precision, you can reduce the interval to every few seconds, but keep in mind this will increase the load on your gateway if many scripts are running concurrently.

With a well-organized tag structure and proper namespacing, I’ve been able to track the runtime of multiple components using just a single, centralized gateway script. It’s easier to maintain and scale that way.

Performing Mathematical Calculations

This one has saved me hours, if not days, of manual processing. Often in my projects, I’ve needed to compute values like energy consumption, flow integration, or average sensor readings after a process has finished running. Instead of exporting all the data, processing it elsewhere, and then reimporting it into the database, I use tag event scripts to do all the heavy lifting inside Ignition.

Imagine this: You have a process that runs 16 times a day across 16 machines. Without automation, you’d have to extract and process all that data externally every single day. But with a tag change script in place, I let Ignition handle the math, store the results, and update the database, all automatically. I just wait for the daily report to land.

That’s the power of automation in industrial control systems: doing more with less effort.

Here’s an example:
Tag scripting integration

Updating Database Records

Tag scripting in Ignition also opens the ability to interact directly with databases. You can read from, write to, or update records using built-in scripting functions like system.db.runPrepQuery, runPrepUpdate, or even Named Queries.

DB Update with tag scripting

In my workflow, I often need to:

  • Fetch previously logged data to reference in calculations
  • Store new cycle data with results (e.g., total energy used, total flow)
  • Update incomplete records after a process ends

Using Named Queries with caching enabled helps to reduce the system load, especially when scripts run frequently. Organizing tags for related components into logical folders also allows you to design reusable gateway scripts that handle multiple calculations centrally.

The Key Insight:

Find what’s common among your tags, maybe it’s the same tag path structure or shared calculation logic and build scripts around those patterns. This dramatically improves your scripting efficiency and makes long-term maintenance easier.

Conclusion

When used properly, tag event scripting is a game-changer. It empowers you to automate tasks like runtime tracking, mathematical processing, and real-time database updates, all within the SCADA system itself. This is especially useful when building custom MES features like:

  • Downtime and uptime tracking
  • Maintenance duration logs
  • OEE parameter calculations
  • Shift-based performance summaries

Whether you're managing a small boiler or orchestrating an entire production line, tag event scripting gives you that next level of control and flexibility.