--- alias: user-guide-automation-business-scenarios-building-structure tags: - automation - connect iot description: "This documentation outlines a JSON format for defining business scenarios and their execution steps" --- # Business Scenario (JSON) The metadata will define the actions and steps that are defined in the scenario, It will also define the outcome of the scenario. The metadata containing all the information regarding a Business Scenario, how it is started, terminated, what it is expected to do and so on. It is expected for this format to be respected for the scenario to properly work. | Name | Description | Mandatory | Type | Possible Values | Default Value | | ---------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------- | -------------------------------------------------------------------------------------- | ---------------------------------------- | ------------- | | start | Initial step to start the execution. This field is mandatory and must reference an existing step in the `steps` list | Y | `String` | | | | finally | Optional step to execute when no more steps are left in the `start` execution | N | | | | | end | Optional step to execute/commit the result of the scenario. It is important to use this when a `resultType` is defined and therefore asking the user before changing the system | N | `String` | | | | steps | List of steps available to be executed within the context of the scenarios | Y | [BusinessScenarioStep](steps/index.md)`[]` | | `[]` | | resultType | Type of result expected to result from this scenario. Used to generate some steps after the end flow
`MasterData` - Automatically generates the necessary steps to ask the user to load the master data
`Script` - Automatically generates the necessary steps to ask the user permission to execute the result script that may change the system
`Custom` - Doesn't generate any additional step after the end flow | N | `Enum` | `Custom`
`MasterData`
`Script`
| `Custom` | !!! info *The list of steps doesn't need to be ordered. The execution follows a linked list approach * The first step to execute is the one referenced in the `start` property *When no more `next` step is defined, the engine will start executing the step referenced in the `finally` property * When the `finally` steps are finished (or no `finish` step is configured), the `end` step is executed after all pre-configured steps from the result type (if any) ## Example snippet ```json { "start": "CheckIfUserIsIntegrationUser", "resultType": "Script", "end": "DeployManagers", "steps": [ { "name": "CheckIfUserIsIntegrationUser", "type": "Script", "resultKey": "selectedUser", "settings": { "script": [ "if(!this.securityService.user.IsIntegrationUser) {", " throw new Error('This scenario can only be executed by a User that is an Integration User');", "}", "this.securityService.user" ] }, "next": "Mode" }, { "name": "Mode", "type": "Question", "resultKey": "selectionMode", "settings": { "message": "Do you wish to have a manual selection with ',' separated Manager Names or the interactive mode?", "dataType": "Enum", "settings": { "enumValues": [ "Manual", "Interactive" ] }, "defaultValue": "Interactive" }, "next": "ModeCondition" }, (...) { "name": "DeployManagers", "type": "Script", "settings": { "script": "${script(./scripts/mass-deploy/mass_deploy.ts)}" }, "next": "" } (...) ] } ```