StateFlow service

Learn the key concepts and usage of the StateFlow service.

Introduction

A StateFlow is a sequence of steps that transforms static data into dynamic processes aimed at driving business outcomes, such as routing jobs to the appropriate employee or soliciting approvals from managers.
The StateFlow service helps you create your tailored business processes by defining states, approvers and transitions.

Key features

  • Defining StateFlow You can define your custom flow for your business processes by defining states containing approvers and transitions.
  • Managing StateFlow state with a State You can create a State to manage the state of resource transitions. Only valid approvers can update a State's status so you can manage your process properly.

Key concepts

  • StateFlow: The data type allows you to define states to be transitioned, authorized approvers for the steps and actions to be taken at the time of transition.
  • State: The data type to manage the state of a resource in your schema. Each State is associated with a specific resource ID in your data and a StateFlow ID you created. Based on the StateFlow, State transitions through the steps of that resource.
  • Approvers: The resource IDs such as users and roles who can update the State with actions and transition steps of the StateFlow.
  • Transitions: The paths of the StateFlow which contains actions to determine the next destination of the StateFlow. Transitions can have multiple paths. You can specify the next step of the StateFlow by assigning an ID of the step in the StateFlow.

StateFlow overview

The diagram illustrates how a StateFlow is set up. Each component is described below.

Tutorials – Create StateFlow Overview

Key parameters of StateFlow

StateFlow

Fields

NameData TypeDescription
idID!

An identifier of this StateFlow rule. This id field is used to specify the StateFlow in newState() mutation.

nameStringThe name of the StateFlow
stateTransitionModels

[[stateTransitionModel!]]

The list of state transition models

StateTransitionModel

Fields

NameData TypeDescription
approvers[[Approver!]]Permission settings of users who can trigger the transition
descriptionStringThe description of State transition model
nameStringThe name of State transition model
transitions[[Transition!]]Defines the next steps that can be transitioned from this state

Approver

Fields

NameData TypeDescription
idID!

UUID of a user or a group that can trigger the transition with moveState() mutation

conditionStringCondition of approver

Transition

Fields

NameData TypeDescription
actionString!

Name of the action. This action field is used to specify which transition to take in moveState() mutation.

destinationString!

The specifier to which the State transits. This should match one of the step.ids.

Configuration of StateFlow

StateFlows are made of a set of steps. When you design your stateflow, steps is the actual object you need to create by defining approvers and transitions as a list.

Here's the sample of steps.

As described in the Key concept, approvers are IDs of your resources to update State. This can be user ID, roles or groups -- whatever the resource ID to update the Ticket. When moveState mutation is performed, StateFlow service will verify the user with the approvers and the transition will be made only when the ID of the user matches to approvers or the user belongs to at least one of the resources specified in approvers.

For a step by step guide to set up StateFlow, please visit Setting up StateFlow.

<span><span style="color: var(--shiki-token-function)">sampleStateFlowSteps</span><span style="color: var(--shiki-color-text)">:</span></span>
<span><span style="color: var(--shiki-color-text)">[</span></span>
<span><span style="color: var(--shiki-color-text)">  {</span></span>
<span><span style="color: var(--shiki-color-text)">    </span><span style="color: var(--shiki-token-string)">id</span><span style="color: var(--shiki-color-text)">: </span><span style="color: var(--shiki-token-comment)">&quot;InitialState&quot;</span><span style="color: var(--shiki-color-text)">,</span></span>
<span><span style="color: var(--shiki-color-text)">    </span><span style="color: var(--shiki-token-string)">name</span><span style="color: var(--shiki-color-text)">: </span><span style="color: var(--shiki-token-comment)">&quot;RequestForApproval&quot;</span><span style="color: var(--shiki-color-text)">,</span></span>
<span><span style="color: var(--shiki-color-text)">    </span><span style="color: var(--shiki-token-string)">approvers</span><span style="color: var(--shiki-color-text)">: [</span></span>
<span><span style="color: var(--shiki-color-text)">      {</span></span>
<span><span style="color: var(--shiki-color-text)">        </span><span style="color: var(--shiki-token-string)">id</span><span style="color: var(--shiki-color-text)">: &lt;userX_UUID&gt;</span></span>
<span><span style="color: var(--shiki-color-text)">      }</span></span>
<span><span style="color: var(--shiki-color-text)">    ],</span></span>
<span><span style="color: var(--shiki-color-text)">    </span><span style="color: var(--shiki-token-string)">transitions</span><span style="color: var(--shiki-color-text)">: [</span></span>
<span><span style="color: var(--shiki-color-text)">      {</span></span>
<span><span style="color: var(--shiki-color-text)">        </span><span style="color: var(--shiki-token-string)">action</span><span style="color: var(--shiki-color-text)">: </span><span style="color: var(--shiki-token-comment)">&quot;Approve&quot;</span><span style="color: var(--shiki-color-text)">,</span></span>
<span><span style="color: var(--shiki-color-text)">        </span><span style="color: var(--shiki-token-string)">destination</span><span style="color: var(--shiki-color-text)">: </span><span style="color: var(--shiki-token-comment)">&quot;UserXApprovedState&quot;</span></span>
<span><span style="color: var(--shiki-color-text)">      }</span></span>
<span><span style="color: var(--shiki-color-text)">    ]</span></span>
<span><span style="color: var(--shiki-color-text)">  },</span></span>
<span><span style="color: var(--shiki-color-text)">  {</span></span>
<span><span style="color: var(--shiki-color-text)">    </span><span style="color: var(--shiki-token-string)">id</span><span style="color: var(--shiki-color-text)">: </span><span style="color: var(--shiki-token-comment)">&quot;UserXApprovedState&quot;</span><span style="color: var(--shiki-color-text)">,</span></span>
<span><span style="color: var(--shiki-color-text)">    </span><span style="color: var(--shiki-token-string)">name</span><span style="color: var(--shiki-color-text)">: </span><span style="color: var(--shiki-token-comment)">&quot;UserXApproved&quot;</span><span style="color: var(--shiki-color-text)">,</span></span>
<span><span style="color: var(--shiki-color-text)">    </span><span style="color: var(--shiki-token-string)">approvers</span><span style="color: var(--shiki-color-text)">: [</span></span>
<span><span style="color: var(--shiki-color-text)">      {</span></span>
<span><span style="color: var(--shiki-color-text)">        </span><span style="color: var(--shiki-token-string)">id</span><span style="color: var(--shiki-color-text)">: &lt;userY_UUID&gt;</span></span>
<span><span style="color: var(--shiki-color-text)">      }</span></span>
<span><span style="color: var(--shiki-color-text)">    ],</span></span>
<span><span style="color: var(--shiki-color-text)">    </span><span style="color: var(--shiki-token-string)">transitions</span><span style="color: var(--shiki-color-text)">: [</span></span>
<span><span style="color: var(--shiki-color-text)">      {</span></span>
<span><span style="color: var(--shiki-color-text)">        </span><span style="color: var(--shiki-token-string)">action</span><span style="color: var(--shiki-color-text)">: </span><span style="color: var(--shiki-token-comment)">&quot;Approve&quot;</span><span style="color: var(--shiki-color-text)">,</span></span>
<span><span style="color: var(--shiki-color-text)">        </span><span style="color: var(--shiki-token-string)">destination</span><span style="color: var(--shiki-color-text)">: </span><span style="color: var(--shiki-token-comment)">&quot;done&quot;</span></span>
<span><span style="color: var(--shiki-color-text)">      }</span></span>
<span><span style="color: var(--shiki-color-text)">    ]</span></span>
<span><span style="color: var(--shiki-color-text)">  },</span></span>
<span><span style="color: var(--shiki-color-text)">  {</span></span>
<span><span style="color: var(--shiki-color-text)">    </span><span style="color: var(--shiki-token-string)">id</span><span style="color: var(--shiki-color-text)">: </span><span style="color: var(--shiki-token-comment)">&quot;done&quot;</span><span style="color: var(--shiki-color-text)">,</span></span>
<span><span style="color: var(--shiki-color-text)">    </span><span style="color: var(--shiki-token-string)">name</span><span style="color: var(--shiki-color-text)">: </span><span style="color: var(--shiki-token-comment)">&quot;ApprovedByAll&quot;</span></span>
<span><span style="color: var(--shiki-color-text)">  }</span></span>
<span><span style="color: var(--shiki-color-text)">]</span></span>
<span></span>

Changing states with State

The diagram below illustrates how a StateFlow transition works using State from an implementation perspective. newState and moveState are both described below.

Tutorials – Use StateFlow Concept

Key fields of State

State

Fields

NameData TypeDescription
currentStateString

An identifier of the current step of this state. This should match one of the step.ids.

idID!
resourceIDString

An identifier of the record that this state is associated to. This should match one of the UUIDs of the record in Tailor DB.

stateFlowStateFlowAn identifier of the stateFlow from which this State is generated

newState

In Tailor Platform, the state of a particular record in Tailor DB is managed by a State.

You can think of a State as a record of the state of a resource that is managed according to your stateFlow at a particular point in time.

To create a State, you need to execute the newState mutation with the stateFlow ID, and the resource ID that you want to manage.

When a State is created, both a stateFlow and the resource are tied together, and the initial step ID in the stateFlow steps will be automatically assigned to the currentState field in the created State. In the case of the "sampleStateFlowSteps" example provided above, the initial state is InitialState.

moveState

When you want to change the state of the record according to the stateFlow, you need to execute moveState mutation for the State.

As defined in the associated stateFlow, the state can only transition to the steps that is defined in the transitions of your steps. Also, moveState need to be executed by a user defined in approvers in the steps. This means in the case of sampleStateFlowSteps above, only userX can perform moveState and move the step. Since the steps dictates the possible transition for each step, the state cannot move from InitialState to done directly.

Learn more