Variable Scopes
In the Studio and throughout your app, there are various different namespaces or scopes. This is a way of qualifying access to particular variables throughout your experience. The general best practice is to restrict your variable to least level of access you need in order to make your experience work. We will talk more about that below.
Some namespaces are editable and others are set at the beginning of the experience and cannot be modified.
High-Level Scopes
On each Journey there are some high-level scopes:
- Session - Contains start parameters and session level variables.
session.variableName
- Profile - contains profile level configuration variables. For more information, see Tying Variables to Deployments.
profile.variableName
- Theme - contains theme level configuration.
theme.variableName
- Activities - contains a list of all loaded activities.
activity.variableName
- ActivityGroups - contains a list of all loaded activity groups.
activityGroup.variableName
Many of these high-level scopes are used for app configuration and not really meant to be modified within your experience. The one main exception is Session where we can store variables that are able to accessed on any Web Flow, Web Page, Chat Bot, Voice Bot, or Event.
Note: While both Configuration and Profile scopes are modified in Settings, the Configuration scope contains information about resources while Profile contains variables at the profile-level.
Defining Session-Level Variables
In the context of Airkit apps, the terms Session and Journey are interchangeable. Session- or Journey-level variables are set in the Journey Builder. If you donโt see the Journey section on the right click anywhere on the stage.
Under variables you can click the '+' icon and add session-level variables. These variables will be available most places throughout the app, but remember they are not accessible within Connections Builder โย you would need to pass them into a connection.
Working With Scopes Within Your Web Flows
When working within your Web Flows and Web Pages, you might want to create variables to store values throughout your application. In general, the flow of the variable scoping looks like this:
-
Session (Journey) - accessible Everywhere.
-
Activity Group (Web Flows/Chat Bots/Voice Bots)- accessible to all activities within the activity group.
- Activity (Web Pages/Decision Menus) - accessible only on the on the current activity.
-
As mentioned above, the general best practice is to try to store you variables at the lowest scope. This will ensure the highest level of reusability of your activities and activity groups.
See documentation on Data Types for information selecting variable type.
To access a variable in a particular scope, for example in creating the text for a label, you put in theย scope.variableName
in the expression editor.
Working With Scope Within Events
Events have their own scope as they do not exist within the context of a particular activity. You can set variables on Events by selecting the Event Source in Journey Builder and adding variables. When you fire an event you can pass in values to the variable.
from within the event, you can then reference that value asย event.foo
ย and get the value passed in.
Working With Scopes Within Custom Controls
When building custom controls, you are able to define what inputs or data is available to the control. During the design of your custom control, any defined inputs will be available on theย controlย namespace. For example, if your custom control has an input namedย title
ย , thenย control.title
ย is how youโd reference that variable within the control.
As you implement your custom control, you can pull variables from theย session,ย activityGroup, orย activityย contexts.
Working With Scopes Within Connections
Connections exist as independent steps. They have access to all the inputs passed in but do not have access to things like session, even if they are run from a session. Also, future data operations have access to all the outputs created by previous data operations. This means that if you create a transform in the first step. You can still access the return value of that transform in the 5th step without having to do anything special.
Profile Variables
Your app can contain different profiles. Each profile has a unique set of values and resources associated with them. Talking about profiles in general is a whole different topic, but let's talk about how to create a profile-level variable and modify it.
Go to Journey Builder and start like you would be creating a session-level variable.
Once you have the variable created, right click on it. Selectย Convert To Settingย from the dropdown.
The little symbol next to the variable name indicates that it is a profile level-variable. Once youโve set it to a profile variable, we can adjust the value of the profile variable in Settings. Scroll down the bottom until you seeย App Settings, you can insert a value in the value section.
You can change the value ofย configVar
ย for each different app profile. You can then use this variable throughout your cards asย profile.configVar
. Profile variables have the same access restrictions as session-level variables.
Updated almost 2 years ago