Executing a Scenario
You can execute individual scenarios using the JS API.
There are two ways to do this: from a scenario object you have loaded via a ScenarioObserver or from the view object, passing in a scenario id. In both cases you can specify the execution mode to submit the job with, this defaults to RUN. Both methods submit the execution job asynchronously and return a Promise object which resolves when the job has been successfully submitted or gets rejected if the job could not be queued.
The following is an example of executing a scenario directly from the scenario object. It uses a custom execution mode named FAST_MODE:
insight.getView().withFirstScenario() .withSummaryData() .notify(function (scenario) { scenario.execute('FAST_MODE') .then(function () { console.log('scenario successfully queued'); }) .catch(function () { console.error('scenario failed to queue') }) }) .start();
The next example executes a scenario from outside of a
ScenarioObserver. First it looks up the
id of the first scenario in the selection. Then it uses that together with the custom execution mode name, FAST_MODE:
var view = insight.getView(); view.getScenarioProperties(0) .then(function (props) { return props.getId(); }) .then(function (scenarioId) { return view.executeScenario(scenarioId, 'FAST_MODE'); }) .then(function () { console.log('scenario successfully queued'); }) .catch(function (error) { console.error('scenario failed to queue'); });