Set Scenario Properties

This task sets a scenario property (key and value pair) for the specified scenario. It takes as input:

  • a scenario Id

  • a property key

  • a property value

@Configuration
public class Tasks {
    @Bean
    public ScriptedTaskDescription setScenarioPropertyTask() {
        ScriptedTaskDescription task = new ScriptedTaskDescription("SetScenarioProperty", "Set Scenario Property");
        task.setDescription("Set a property for the selected scenario");
        task.getScript()
            .addStatement(AskInputStatement.of("scenario", true, JobInputType.scenarioId(WRITABLE)))
            .addStatement(AskInputStatement.of("property name", true, JobInputType.TEXT))
            .addStatement(AskInputStatement.of("property value", true, JobInputType.TEXT))
            //set property (key and value) from input variables
            .addStatement(SetScenarioPropertyStatement.of(VariableAccessExpression.of("scenario"), VariableAccessExpression.of("property name"), VariableAccessExpression.of("property value")))
            //Make the task return a result, which is a string representing the new property, having as key the value entered in "property name" and as value what is entered in "property value"
            //using the formatting "Scenario property[{property name}] new value is: {property value}"
            .addStatement(SetTaskOutputStatement.of("result",
                StringExpression.concat(
                    StringExpression.of("Scenario property["),
                    VariableAccessExpression.of("property name"),
                    StringExpression.of("] new value is: "),
                    ScenarioPropertyExpression.of(VariableAccessExpression.of("scenario"), VariableAccessExpression.of("property name")))
                ));
        return task;
    }
}

The generated web client component for this task is the following:

Note that it is possible to create a scripted task to fetch the value of a scenario property by using ScenarioPropertyExpression. In this case, we are getting the property that was just created, so we use the key that was entered in "property name" by using VariableAccessExpression.of("property name"). We can get the value of a property that we know is already defined in the scenario. For instance, to get the value of the scenario property "property1", we can use the following expression: ScenarioPropertyExpression.of(VariableAccessExpression.of("scenario"), StringExpression.of("property1"))