Using mabl, you can share variables between journeys within the same plan.
- creating test data with randomly generated variables such as user IDs or emails that you would like to delete in a different journey at the end of the plan
- generating variables in one journey that you would like to then validate in a different journey in the same plan such as creating a user and then assigning it to different roles
To share variables between journeys, you would typically take the following steps:
- Create the journey that generates the variables you would like to share
- Configure the journey to share variables
- Create other journeys that will make use of the shared variables
- Add all those journeys to the same plan
You can share all variables that generated their value during a journey run from the following sources:
- string templates
- element properties
- mabl mailbox
- API steps
Creating a variable from a random string template
We refer to those variables as journey-generated and to configure the journey to share them, do the following:
Go to the journey details and click to edit the journey.
Edit journey details
Then, enable the variable sharing as shown below.
Enable sharing variables
Next step is to create the journey that we will be passing the shared variables onto. Since a journey does not know what variables it will receive upon execution, we need to create and use data-driven variables with default values as placeholders. The variable names must match the names of the variables that are being passed onto the journey. Names are case sensitive.
Creating a data-driven variable named "userId"
During the journey run, mabl will overwrite the default values with values from the variables passed onto the journey, as long as the variable names are an exact match.
Variable name conflict resolution
If multiple journey runs generate and share the same variables, but with different values, then the last journey run that completed would override the variable values set by prior journey runs. This is also true if the plan has multiple browsers, run multipliers and/or the journey has a DataTable with multiple scenarios associated with it.
If multiple values are passed to a journey for the same variable, the following order takes precedence: environment < journey share < DataTable. The value coming from the DataTable scenario will overwrite all other values.
To run the created journeys and share variables between them, you need to also add them to the same plan.
In order to pass variables from one journey run to another journey run, you need to ensure that the journey run passing the variables succeeds prior to journeys expecting those variables starting.
One way to achieve this is to place all journeys in a sequential stage that will run the journeys in the given order. Another way to setup the plan is to have all journeys sharing variables in one stage and place journeys expecting those variables in follow on stages.
Sharing variables between journeys in a plan works best when the plan runs in a single browser on a single environment and without a run multiplier to ensure that the journeys sharing variables will run just once within the plan.