# Journey Mapping

### Overview

The **Journey Mapping** Data Operation is used to map [Journeys](https://docs.airkit.ai/?q=the-journey-model) into either a new or existing sessions. This makes it possible to call on a Data Flow in order to create new sessions or interact with existing ones, streamlining the process of, for instance, mutating the state of a previously established session.

As part of the process of mapping Journeys, the Journey Mapping Data Operation provides a means of fine control over how this next Journey will be Identified. This can be done either by defining the sessionID directly, or – if matching an Identifier to an existing session – via an Identifier that was set by [the Set Identifier Action](../actions/the-set-identifier-action).

![organizing info](https://1191388742-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhOn9CLWoV9VfJeM5EDAa%2Fuploads%2Fgit-blob-6c1f77193182361d29d6bbbfd1426e1c7f9ff7fa%2Fthe-journey-mapping-data-operation-v1715-0.gif?alt=media)

### Use Cases

* Making it possible for users to send a partially-completed form to another [Actor](https://docs.airkit.ai/?q=the-actor-model) to complete
* Finding and pivoting to existing sessions in order to better consolidate information
* Allowing external users to activate new Journeys by accessing a Data Flow build into a [Portal](../studio/builder-bar/portal-builder)

### Data Operation Properties

#### Journey Behavior

This section defines how the initial Journey will pivot: by starting an entirely new Journey, or by looking up and mapping to an existing Journey.

**Start a New Journey**

When this option is selected, the Journey Mapping Data Operation will attempt to start a brand-new Journey. This data operation also provides, through the Journey Identifier Expression, a means to define how the new Journey will be Identified.

It's possible for this to contradict with the mandate to start a new Journey if the given Identifier isn't unique: by definition, all Journey Identifiers must be one-of-a-kind so that they can be used to Identify individual Journeys. Upon selecting the **Start a New Journey** option, Dropdown menu appears that makes it possible to define how such a contradiction should be resolved, should it occur:

![organizing info](https://1191388742-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhOn9CLWoV9VfJeM5EDAa%2Fuploads%2Fgit-blob-3e0ae2a12c54282a1ee819f7a1d3fdce5115302c%2Fthe-journey-mapping-data-operation-v1715-1.gif?alt=media)

There are two options if the Identifier is found in an existing Journey:

* Replace Current Journey - Funnel into the Journey associated with the Identifier intended for the new Journey that was going to be created.
* Abort - Do not pivot Journeys at all and continue as though this data operation was never called upon.

Note that in neither case does a new Journey get created; it is not possible to create a new Journey that has the same Identifier as an established Journey.

**Lookup and use an existing Journey**

When this option is selected, the Journey Mapping Data Operation will search for an existing Journey that matches the Journey Identifiers defined in a later section \[Journey Identifier Expression. If such a Journey exists, it will funnel the user into that established Journey.

However, it might not always be the case that such an established Journey exists. Upon selecting the **Lookup and use an existing Journey** option, a Dropdown menu will appear, making it possible to define how the data operation will be resolved, should this occur:

![organizing info](https://1191388742-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhOn9CLWoV9VfJeM5EDAa%2Fuploads%2Fgit-blob-eb8395f7b85bcfa05ee3284fddebda773878a49d%2Fthe-journey-mapping-data-operation-v1715-2.gif?alt=media)

There are two ways to resolve the data operation if there is no existing Journey to replace:

* Create New Journey - Start a brand-new Journey defined by the given Identifier.
* Abort - Do not pivot Journeys at all and continue as though this data operation was never called upon.

#### Start Parameters

The _Start Parameters_ section defines what information will be passed from the current Journey to the next. It accepts data in the form of a JSON object or an [App Object.](../working-with-data/airdata/airdata-app-objects) Data passed here is stored under `session.start`.&#x20;

#### Journey Identifier Expression

This section defines the Identifier(s) that define the Journey being pivoted to. In the case of starting a new Journey, this will create an Identifier for that Journey; in the case of pivoting to an existing Journey, this defines how to Identify which established Journey will replace the initial Journey.

There are three types of Identifier Expressions:&#x20;

* Text - Any unique combination of numbers and text that can be used to Identify the session.
* Journey ID - Also known as the `session_id`, this is the primary identification assigned to a Journey when it first begins.
* Phone - The phone number associated with the Actor of the Journey.

These Identifier Expressions can be selected from the dropdown menu to the immediate right of the expression:

![organizing info](https://1191388742-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhOn9CLWoV9VfJeM5EDAa%2Fuploads%2Fgit-blob-f422049f80f670188b02484e2da3e9d5c260880c%2Fthe-journey-mapping-data-operation-v1715-3.gif?alt=media)

The expression itself parses [Airscript](https://github.com/airkit/airkit-docs/blob/master/docs/v17-15/what-is-airscript.md?).

While all Journey Identifiers must be unique, a single Journey can have multiple Identifiers, and arbitrarily many can be associated with the new Journey. Click on the '+' icon at the bottom of the **Journey Mapping Data Operation** section to add a new Journey Identifier Expression. Click on the trash icon to the right of an Identifier Expression to delete it.

### Results

The Journey Mapping Data Operation differs from many other Data Operations in that it cannot be properly tested within [Connection Builder.](../studio/builder-bar/connection-builder) It is not meant to return output as much as it is meant take an action, that is, pivot from one Journey to another. However, once an app is published, it is possible to access the output of the Journey Mapping Data Operation if that output is returned from the [Data Flow](../studio/data-flows) as a whole. This output is an object that contains information pertaining to the Session ID of the new Journey, the Session ID of the old Journey, and when the new Journey is set to expire.
