Dynamic reference considerations
- Last UpdatedJul 31, 2024
- 2 minute read
Dynamic reference scripting is one the biggest causes of deployment failures of StartUp and OnScan execution types.
Rather than placing dynamic referencing scripts in the Startup or OnScan methods, perform dynamic referencing in the Execute method. There are several advantages to using the Execute method with dynamic reference scripting:
-
Deployment is faster.
-
Deployment is more reliable.
-
Deterministic execution order is guaranteed.
-
Off-object and off-engine attributes are available.
-
After a failover occurs, the startup of the redundant engine is more stable and can be faster.
To create a simple dynamic reference script example
-
Create a Boolean attribute.

The attribute shows if the referencing script is complete. In this example you create Ref_Done. IO_Item1 and IO_Item2 are the I/O points referenced in this example.
-
Create the script. The script in this example is called Set_Refs. The script has a trigger type of WhileTrue with a 0 trigger period.

The script is shown below:
If Me.Set_Refs.ExecutionCnt == 2 then
Me.IOItem1.InputSource = "DIObject.Topic." + me.Tagname + ".Item1";
Me.IOItem1.OutputDest = "DIObject.Topic." + me.Tagname + ".Item1";
Me.IOItem2.InputSource = "DIObject.Topic." + me.Tagname + ".Item2";
Me.IOItem2.OutputDest = "DIObject.Topic." + me.Tagname + ".Item2";
Me.Ref_Done = True;
Endif;
This script allows the system to stabilize after going on scan before setting the references. The script executes on the first two scans of the object when the Boolean attribute Ref_Done is false.
As the script is executed, a check is made against the execution count. If the count equals 2, the script performs the referencing operations. After the reference attributes are set on the attributes, the Ref_Done attribute is set to True. At this point the expression for the script is no longer true.
The three attributes set in this script are checkpointed, eliminating the need to run this script except on deployment. The next time the object is started, placed on scan, or failed over, there is no need to recreate the references to the items.