All Products
Search
Document Center

CloudFlow:Inputs and outputs

Last Updated:May 07, 2025

CloudFlow passes data between states in a workflow. A state receives the input provided by the previous state, and returns and passes the output to the next state. This topic describes the inputs and outputs in workflows.

Background information

Data in a CloudFlow workflow flows from one state to another, which is similar to function calls in functional programming. Each state receives input and returns output. The output data is stored in the context. The data flow between states enables the automation of processes in business applications that require complex logic.

Note

Inputs and outputs must be JSON objects. The size of the input and output of a state cannot exceed 64 KiB. If the size of the input and output of a state exceeds 64 KiB, the flow fails to be executed.

Inputs and outputs of executions

Inputs of executions

You must provide information or data to start an execution. The information or data may serve as the input of one or more states. You can access the input of an execution by using the $Context.Execution.Input system expression during workflow orchestration.

For example, the logic of an online student enrollment system consists of three processes: student information collection, student information verification, and student enrollment. Basic student information is required in each process. In this case, you can pass basic student information as the input of the execution and configure the three corresponding states to access the execution input by using the system expression. The following figure shows a sample execution input.

image

Outputs of executions

The output of an execution is the result of a successful execution. You cannot access the output of an execution by using a system variable during workflow orchestration.

Inputs and outputs of states

Inputs of a state

During workflow orchestration, you can use the $Context.Current.Input system expression or its shorthand form $Input to access the input of the current state.

Outputs of states

During workflow orchestration, you can use the $Context.Current.Output system expression or its shorthand form $Output to access the output of the current state. Take note that the shorthand form $Output can be used only in the scopes of output constructors.

Constructors

System expressions that can be used in constructors

The following system expressions can be used in constructors:

  • $Context: The lifecycle of $Context is the same as the whole execution period of the workflow. For more information about $Context, see Data passing.

  • $Input: The lifecycle of $Input starts when the workflow enters the state and ends when the workflow exits the state. $Input is the shorthand form of $Context.Current.Input.

  • $Output: The lifecycle of $Output starts when the workflow enters the Task call response state, and ends when the workflow exits the state. $Output is the shorthand form of $Context.Current.Output.

  • $Global: The lifecycle of $Global is the same as the whole execution period of the workflow. For more information about $Global, see Global variables.

Important
  • A key that ends with .$ in an input constructor, output constructor, or parameter constructor must be assigned a value in the form of an expression. Otherwise, an error occurs.

  • When you use built-in functions or system variables that start with $, append .$ to the end of the variable keys to ensure that the variables are not treated as strings.

  • An input or output constructor supports up to 10 layers of built-in function nesting.

The following figure shows the lifecycles of the $Input, $Output, $Context, and $Global system expressions, and the assignment processes in different states.

image
  • $Input is the input of the execution.

  • In the preceding figure, $Input=InputConstructor($Context,$Global) indicates that within the scope, InputConstructor can refer to $Context and $Global and extract information from them. The construction result is assigned to $Input.

  • $Output is the result of the Task call. If the call is initiated in asynchronous callback mode, the value of $Output is the result of the callback.

  • $Output=OutputConstructor($Context,$Global) indicates that within the scope, OutputConstructor can refer to $Context and $Global and extract information from them. The construction result is assigned to $output.

  • $Global indicates global variables, which are accessible throughout the execution period of the workflow.

  • $Global=Merge($Global,GlobalConstructor($Context,$Global)) indicates that the variables constructed by the global constructor are merged with the existing variables in $Global and then all the variables are stored in $Global to update shared global variables.

  • $Context remains valid throughout the execution.

InputConstructor

InputConstructor constructs the input of a workflow. The expressions of InputConstructor are different from the conditional expressions of Choice states. Conditional expressions can return only Boolean values, whereas the expressions of InputConstructor can return any value. You can use the following system variables in the state InputConstructor:

  • $Context

  • $Input

  • $Global

Important

When multiple input configurations exist, the input priority is in the following descending order: InputConstructor, ItemsPath, and ItemConstructor.

The following state machine definition provides an example on how to use InputConstructor.

Type: StateMachine
Name: test3-tx
SpecVersion: v1
StartAt: InvokeFunction1
States:
  - Type: Task
    Name: InvokeFunction
    Action: FC:InvokeFunction
    TaskMode: RequestComplete
    InputConstructor:
      FieldA.$: $Context.Execution.Input
      FieldB: World
      FieldC.$: length($Context.Execution.Input)
      FieldD.$: $Global.InvokeFunctionPayload
    Parameters:
      resourceArn: >-
        acs:fc:cn-hangzhou:123456:functions/myFunction1/LATEST
      invocationType: Sync
      body.$: $Input
    End: true
  - Type: Task
    Name: InvokeFunction1
    Action: FC:InvokeFunction
    TaskMode: RequestComplete
    Parameters:
      invocationType: Sync
      resourceArn: acs:fc:cn-hangzhou:123456:functions/myFunction1/LATEST
    GlobalConstructor:
      InvokeFunctionPayload.$: $Output.Body
    Next: InvokeFunction
  • In the preceding example, the data structure of InputConstructor is Map[String]Any.

  • FieldA.$: $Context.Execution.Input indicates that the FieldA key dynamically retrieves the value from $Context.Execution.Input instead of being treated as a string.

  • FieldB: World indicates that the static string 'World' is assigned to FieldB. A value is not dynamically retrieved because the FieldB key does not end with a .$ marker.

  • FieldC.$: length($Context.Execution.Input) indicates that the built-in function length is used to retrieve the length of the value in $Context.Execution.Input and that the length is assigned to FieldC. For information about the built-in functions that can be used in constructors, see Built-in functions.

  • The FieldD.$: $Global. InvokeFunctionPayload expression extracts the value of the InvokeFunctionPayload key in the global storage space and passes the value as the FieldD field to the Task state.

OutputConstructor

Compared with InputConstructor, OutputConstructor is executed at a different time and supports more variables in context expressions. For example, you can use only $Context or $Input in an input constructor, whereas you can use $Output in an output constructor to represent the output because a Task call already generates the output. You can use the following system variables in the state OutputConstructor:

  • $Context

  • $Input

  • $Output

  • $Global

The following state machine definition provides an example on how to use OutputConstructor.

Type: StateMachine
Name: test3-tx
SpecVersion: v1
StartAt: InvokeFunction1
States:
  - Type: Task
    Name: InvokeFunction1
    Action: FC:InvokeFunction
    TaskMode: RequestComplete
    Parameters:
      invocationType: Sync
      resourceArn: acs:fc:cn-hangzhou:123456:functions/myFunction1/LATEST
    GlobalConstructor:
      InvokeFunctionPayload.$: $Output.Body
    Next: InvokeFunction
  - Type: Task
    Name: InvokeFunction
    Action: FC:InvokeFunction
    TaskMode: RequestComplete
    Parameters:
      resourceArn: >-
        acs:fc:cn-hangzhou:123456:functions/myFunction1/LATEST
      invocationType: Sync
      body.$: $Input
    OutputConstructor:
      returnID.$: uuid()
      functionResult.$: $Output
      functionResultStr.$: jsonToString($Output)
      executionInput.$: $Context.Execution.Input
      lastOutput.$: $Input
      demo.$: $Global
    End: true
  • In the preceding example, the data structure of OutputConstructor is map[string]any.

  • functionResult.$ dynamically retrieves the state output, executionInput.$ dynamically retrieves the execution input, and lastOutput.$ dynamically retrieves the state input.

  • returnID.$ retrieves the unique ID, and functionResultStr.$ retrieves a string that is created from the state output.