Skip to content
  • There are no suggestions because the search field is empty.

How to Print the OnChange Event Handlers Associated with a DataHub tag in Scripting

How can I print the OnChange event handlers I have associated with a tag within DataHub scripting?

There is a command that returns the a list of s-expressions that will be executed in order when the symbol value changes.  The command is "when_set_fns" and takes a single argument which is the DataHub Symbol.
Here are a few examples.  These can be executed directly from the script log.
  1. princ(when_set_fns(#$DataPid:PID1.Mv));
  2. princ(when_set_fns(symbol("DataPid:PID1.Mv")));
We recommend using option 2 if your tag has spaces in the name.
The output below is an example for a tag with a single OnChange event.
(#0=(_inform_datahub_) #0# #1=({TestOnChange (_ChangeFunctions (DataPid:PID1.Mv . #1#)) (_CustomSubmenu) (_MenuActions) (_SubMenus) (_TimerIDs) (lastTime . 44697.596081863433938)} samplemethod DataPid:PID1.Mv))
In this example, "TestOnChange" is the name of the class and "samplemethod" is the name of the method that will be called when the tag changes.  These will be executed in order when the symbol value changes.
Another example is provided as a stand alone script and can be downloaded below. This script prints the events every 5 minutes to the script log.