Please note : This help page is not for the latest version of Enterprise Architect. The latest help can be found here.

Dynamic Simulation with Javascript

The Corporate and suite editions of Enterprise Architect have the capability of using Javascript to evaluate guards, effects and other pieces of behavior within the Simulation context. This provides for a fully automated, intelligent execution of your state or activity model, with fine control over breakpoints, execution speed and simulation variables.

Important: All Simulation level variables that will be referred to or evaluated at execution time must be prefixed with "sim." or with "this."; for example:


All the above are valid Simulator variables. These variables are shown in the Local Variables window without the "sim." prefix.

You would generally use the "sim." prefix to reference any global or control variables not declared in the owning Class. You would generally use the "this." prefix to reference attributes of the owning Class.

Some examples of where and how you can set Simulation behavior using Javascript are shown below. See the EAExample.eap model that comes with Enterprise Architect for some more examples. Also see the Learning Center for further information on setting up and working with Javascript in Simulations.

Using Javascript



See also

Analyzer Script Input

If you enter Javascript code into the Execution Analyzer window "Input" field, this code will be injected into the Simulation and executed before the Simulation starts. This is useful for establishing COM variables, global counters, useful functions and other initialization.





Transition and Control Flow Guards

This is the workhorse of the Simulation functionality. As Enterprise Architect evaluates possible paths forward at each node in a Simulation, it tests the Guards on outgoing transitions and control flows and will only move forward if there is a single true path to follow - otherwise the Simulation is considered "blocked" and manual intervention is required.  You must use the "==" operator to test for equality.





Element Behavior

Entry and Exit behavior may be defined for States. Such code will execute at the appropriate time and is useful for updating Simulation variables and making other assignments.





Using COM

One very important feature of the implementation of Javascript in Enterprise Architect's simulator is that it supports the creation of COM objects. This provides the ability to connect the running Simulation with almost any other local or remote process and either influence the Simulation based on external data, or potentially change data or behavior in the external world based on the current Simulation state (eg. update a mechanical model or software simulation external to Enterprise Architect). The syntax for creating COM objects is shown below."Odd Even";

var logger = new COMObject("MySim.Logger");


logger.Log("Simulation started");




Signalled Actions

It is possible to raise a signalled event (trigger) directly using Javascript. The BroadcastSignal() command is used to raise a named trigger which may influence the current state of a simulation. For example the following fragment raises the signal (trigger) named "CancelPressed".




Note that a trigger named "CancelPressed" must exist within the current simulation environment and must uniquely have that name.




The IS_IN(state) operator returns true if the current simulation has an active state  in any thread matching the passed in name. For example it is possible to write code such as the following to conditionally control execution:


if (IS_IN("WaitingForInput"))



Note that the name must be unique within all contexts.




The Trace(statement) method allows you to print out trace statements at any arbitrary point in your simulation. This is an excellent means of supplementing the Simulation log with additional output information during execution.



Learn more