Working with Data Working with Data

Working with Data

Zack Cohen Zack Cohen

Airkit allows you to collect, use, modify, and remit data. This article covers how to work with Data, specifically the following areas:

What is Data?

Data is information that can be stored or used in your application. Data in Airkit has many different data types. Data can be simple types like Text or Number, or complex types like Currency or Datetime. It can also be custom types. Data can be collected from a user or stored in App and used as a configuration.

3 Ways To Store & Access Data

1) Variable & Journey State

Variables are one way to store and access Data. Variables can be defined at different scopes to have different availability throughout an application. The data held in a variable reference can be changed throughout the lifetime of the app based upon events and actions. 

Defining Variables in Namespaces and Scopes

Namespaces refer to regions where we can store data. Scopes are how we access variables in each of the regions. For a detailed understanding, please check out this document on variable scopes. There are several different variable scopes for working with data. Some of them include:

Session - accessible anywhere throughout the app builder and journey builder. They are tied to a specific user's journey.

session.first_name

Defining variables at the session level happens in Journey Builder. Click on the canvas and the inspector will show available session scoped events.

sessionVariablegif.gif

ActivityGroup - accessible to any web page, action, or event within a specific Web Flow.

activityGroup.first_name

To create a variable on a Web Flow, go to App Builder and select a Web Flow in the Tree. In the Inspector under the Variables section, there is a list of available ActivityGroup scoped variables and a button to add new variables.

Activity - accessible to any event or control on a given web page.

activity.first_name

To create a variable on a Web Page, go to App Builder and select the Web Page from the Tree. In the Inspector under the Variables section, there is a list of available Activity scoped variables and a button to add new variables.

When referring to a variable without a scope in a Web Flow, the runtime will attempt to find the variable in the most specific level and work up the chain, checking in activity, then activityGroup, then in session. It is possible to have variables named the same name in multiple scopes so it best to be specific when referring to your variables.

Accessing the Data

Defined data can be used in expression editors throughout the experience. In this case, the activityGroup variable activity_group_name is used to set the text for a label.

ExpressionEditorText.png

Updating values in variables can be done through Set Variable Action on an action or event. This action can happen when a user takes an action, such as entering data into a form, clicking on a button, or responding to a text or voice prompt. Because this action uses an expression editor, Airscript can be used with properly scoped variables in updating variable values.

2) Storing and Looking Up Records with AirData

AirData is a datastore tied to an app's profile where records can be stored for collection or retrieval. Use Data Flows to look up and store your records into AirData App Objects. Airkit Studio has a bunch of ways to work with data stored in AirData.

Seeing AirData in Data Builder

The data stored in AirData can be viewed in the Data Builder. Selecting an object in the Tree will show you the data already in the AirData Table.

AirDataTable.png

Clicking into a table cell will allow modification of data. Once a row has modified data, it will highlight in a light yellow. Changes will be committed on the next save. Add new rows by clicking on the cell to the right of the New text. New rows are highlighted in light green. Just like modified rows, changes will be committed on the next save. Clicking the trash can at the left of a row will mark the row for deletion on the next save.

Retrieving Data with Data Flows

Data from AirData can be accessed through Data Flows in Connection Builder. To retrieve data from the above table, create a new Data Flow in Connection Builder. Select AirData from the dropdown for the first Data Operation. The above AirData App Object is named Teacher, so select that from the dropdown.

AirDataRunResults.png

Clicking Play on the Data Operation will return the query results from the AirData table. In the picture above, there were 5 teachers in the Teachers AirData table. Returning the entire response is possible at this point, but it is also possible to filter out the results by creating another Data Operation of type Transform. Writing something simple like:

objectService.results

will return only the resulting array. Returning the result of the transform will return a List of Teacher Objects. In addition, additional filtering of the list can be done in the Transform using Airscript's Query Expression Syntax to pull out all teachers who have been teaching for at least five years.

FROM teacher
IN objectService.results
WHERE teacher.years_teaching > 5
SELECT teacher

The result of this transform would be all of the teachers who have a value of years_teaching greater than five.

Using Datastores

AirData is stored in Datastores. Datastores are collections of AirData that are kept in a specific environment. Different Profiles can use different Datastores. Each datastore will have its own version of AirData. Create a clone of a Datastore, which is useful when setting up environments for testing. When an app is created, a Datastore is created with it. Switching the Datastore can be done in Configuration Builder.

3) External Systems of Record

External system data can be retrieved, modified, and updated through Connection Builder. This data can be used throughout your App. Our Data Flows can be used to fetch data from any HTTP API. Once data is ingested into the App through the connection it can be treated like any other Variable Data Type. For detailed instructions on how to get external data, check out this article.

Using & Transforming Data

There are two main categories of data in the Studio. Data that needs to be gathered from a user and data that needs to be displayed. Gathering data is about creating Forms and Agreements. When we create a Text Input on a Web Page, Airkit automatically creates a data binding to a text variable on the page. This variable can be displayed on the existing paged, passed to an action like a Data Connection, or an Event. The data can also be passed to future Web Pages in the journey:

GoodMorning1.pngGoodMorning2.png

In this example, the text is retrieved from the user and passed to the subsequent Web Page to be displayed.

In Addition to viewing, Data can be sent to AirData App Objects or external systems through Data Flows.

Data might need to be transformed, actually as it was in the example above. In order to create the Text for the Text Label with the name, the Expression editor for the greeting text contained:

"Good Morning, {{first_name}}"

This is an example of using an escape sequence in the string for the Label to Insert some AirData. There are more examples in Working With Text in Airscript.

More complicated transformations of data are better done in Data Flows in Connection Builder using the Transform Data Operation. This operation can be used for many different things, check out the documentation for more information.

Where to go from here

This is just a basic introduction to working with Data within your app. For additional resources please check out the following pages:

Add comment

Article is closed for comments.