Developing Apama Applications > Developing Apama Applications in Event Modeler > Working with Blocks Created from Scenarios > Setting parameters before creating sub-scenarios
Setting parameters before creating sub-scenarios
When you add a scenario block to a main scenario, the scenario block’s parameters have default values according to their types. For example, the default value of a string parameter is an empty string ("").
After you add a scenario block to a main scenario, you can set initial values for the scenario block’s parameters in the Blocks tab. However, it is important to understand that the values you set are initial values and not default values. During execution of a main scenario, if you want to change the value of a parameter, you must explicitly do so. After you modify the value of a parameter, if you require the parameter to have its initial value, you must explicitly set it to its initial value.
When you call the create operation, the newly created instance’s input variables take their values from the current values of the corresponding scenario block parameters. The current values of the parameters might or might not be the initial values; if you modified a parameter value, the parameter has the last value that was assigned to it. If you then call the create operation, the scenario block assigns that last value to the sub-scenario’s corresponding input variable.
To create a sub-scenario that has the initial parameter values for its input variables, do one of the following:
*If the main scenario has not made any changes to the scenario block’s parameter values, call the create operation.
*If the main scenario has made changes to parameter values, explicitly specify the value of each parameter, and then call the create operation. This is the safest way to ensure that you create the sub-scenario with the values you want. A common mistake is to forget that you changed the value of a parameter in the course of some work. If you then create a new sub-scenario, it has the updated value of the parameter and not the initial value.
For example, consider the following set-up: MyScenarioBlock has three parameters that correspond to three input variables: Input1, Input2, and Input3. The initial value of each parameter is blue. The value of the instance id parameter is the empty string, which means that the scenario block generates the instance IDs for you. In a rule, you can set parameter values and create sub-scenarios as follows:
 
When  true
Then  Input1 = green
Then  create [MyScenarioBlock]
Creates the MyScenarioBlock1;1 instance. The values of the parameters and the values of the input variables in this instance are green, blue, and blue.
 
Then  Input2 = purple
Then  create [MyScenarioBlock]
Creates the MyScenarioBlock1;2 instance. The values of the parameters and the values of the input variables in this instance are green, purple, and blue.
 
Then  Input3 = white
Then  create [MyScenarioBlock]
Creates the MyScenarioBlock1;3 instance. The values of the parameters and the values of the input variables in this instance are green, purple, and white.
 
Then  instance id = MyScenarioBlock1;2
Then  retrieve [MyScenarioBlock]
Makes the second created sub-scenario the context instance. The variables in this instance have the values green, purple, and blue. Note that this is not the same as the current parameter values, which are green, purple, and white. The retrieve operation does not modify the current values of the scenario block’s parameters.
 
Then  Input2 = gold
Then  commit [MyScenarioBlock]
After the commit operation, the values of this sub-scenario’s input variables are green, gold, and blue. The values of the corresponding scenario block parameters are green, gold, and white. The commit operation modifies only the context instance. It does not modify any other sub-scenarios. The commit operation makes only those changes made since the retrieve operation. For example, it does not change the value of Input3 to white.
 
Then  create [MyScenarioBlock]
Creates the MyScenarioBlock1;4 instance. The values of the input variables in this instance are green, gold, and white, which are the current values of the corresponding parameters.
Copyright © 2013-2015 Software AG, Darmstadt, Germany and/or Software AG USA Inc., Reston, VA, USA, and/or its subsidiaries and/or its affiliates and/or their licensors.
Use, reproduction, transfer, publication or disclosure is prohibited except as specifically provided for in your License Agreement with Software AG.