How does simulator methods of BPMN Token stimulation works?

Hi,
Currently i am trying to manually trigger and wait the token of token stimulation for flowing the token only for qualified path.
Wait for element method : this.simulator.waitAtElement(id) is working .
But the method for enter and signal is not working…,that is to start the flow on particular path alone.
Below is the snippet i tried,

 const scope = this.simulator.createScope({
    element: elementRegistry.get(id)
  });
  this.simulator.enter(scope);

Please advise on the above.

Please share a CodeSandbox that reproduces your issue in a way that we can inspect it.

We dont have access to codesandbox in our organisation.
We are trying to control the token flow as interactive stimulation where in every condition flow split, the element will wait at the souce activity and a popup will triggered with all the conditions in the split.When the user choose any condition the token has to flow only on that particular flow.

For Waiting of the token:
this.simulator.waitAtElement(id)

For trigger particular flow:
const scope = this.simulator.createScope({
element:elementRegistry.get(‘Activity_1ondrys’)
});
console.log(scope);
this.simulator.exit({element:‘Activity_1ondrys’,scope:scope});
this.simulator.enter({element:‘Activity_1wfy1pk’})
this.simulator.signal({element:‘Activity_1wfy1pk’});

When executing exit method it throws error as
unhandled error in event listener TypeError: Cannot read properties of undefined (reading ‘name’)
at getElementName (Log.js:42:1)
at Log.js:152:1
at invokeFunction (EventBus.js:519:1)
at push…/node_modules/bpmn-js/node_modules/diagram-js/lib/core/EventBus.js.EventBus._invokeListener (EventBus.js:371:1)
at push…/node_modules/bpmn-js/node_modules/diagram-js/lib/core/EventBus.js.EventBus._invokeListeners (EventBus.js:352:1)
at push…/node_modules/bpmn-js/node_modules/diagram-js/lib/core/EventBus.js.EventBus.fire (EventBus.js:313:1)
at emit (Simulator.js:602:1)
at trace (Simulator.js:579:1)
at Simulator.js:167:1
at queue (Simulator.js:71:1)

TLDR: Learn how the Simulator API works, and you’ll be able to use it, at your own risk. Consider to instead use SimulationSupport instead.


Detailed write-up:

:warning: The Simulator is a low level utility. Use it at your own risk.

:information_source: SimulationSupport is a high-level utility to drive forward the simulation, and hides details that are not relevant to the average user.

The Simulator offers plenty of APIs to inspect the current run-time state, but also drive the simulation state forward.

However:

  • You don’t usually create scopes outside of the simulator (ref)
  • You often times need to reference parent scopes or things will blow up:
    • in the case of entering a scope pass the parent scope, and the actual element to be entered (ref)
    • in the case of exiting a scope, pass the scope and element as context (ref)
1 Like