Skip to main content

Triggering via component behavior or invocation

Workflow supports triggering by setting component behavior in the WeDa editor or via calls to code, SDK, or API.

Configuration Item Description

Enabled

Whether this trigger method is enabled. If disabled, the workflow will not be triggered via this method.

Usage Instructions

By configuring this trigger, the workflow can be triggered via the CloudBase SDK, APIs provided by CloudBase, or by setting component behaviors in the WeDa editor.

Initiate Invocation

Initiating Invocation via Mini Program or CloudBase Cloud Function

Workflows configured with invocation triggers can be initiated within Mini Programs or CloudBase Cloud Functions using the Mini Program SDK or wx-server-sdk provided by WeChat. The current invocation trigger operates synchronously; calls will wait for the workflow execution to complete before returning, and will deliver the workflow's execution output to the caller.

Use the following methods to invoke the workflow:

# Initiating Invocation in Mini Programs or Cloud Functions
# Invoking Workflows Using the callFunction Method + Specified Parameters

wx.cloud.callFunction(
"name":"cloudbase_module", # The name must be cloudbase_module
"data":{
"name":"sywxzfapifqzf_xxxx", # The name is the workflow identifier, which can be obtained from workflow properties or specified during workflow creation.
"data":{ # Invocation parameters, supporting JSON-formatted parameters, which can be obtained via the trigger node's output within the workflow
"hello":"world"
}
}
)

The invocation description is as follows:

  • Reuse the callFunction method in Mini Programs or Cloud Functions. Mini Programs or Cloud Functions do not require a base library upgrade.
  • The name parameter for invocation must be cloudbase_module
  • Within the data input parameter, name is the identifier of the workflow to be invoked, which can be obtained by querying the workflow's properties and can also be specified during workflow creation.
  • Within the data input parameter, data represents the parameters passed to the workflow. The passed parameters can be any content in JSON format and can be obtained via the trigger node's output.

The structure of the returned result after invocation is as follows:

{
"result":{
"hello":"world"
},
"requestID": "09bab203-008a-407d-a12a-ca4792dc6ccb" // Request id during workflow invocation
}

The description of the returned result is as follows:

  • The returned result is in the result structure, which is identical to the cloud function's return result structure.
  • requestID is the execution request id of the workflow.

Before initiating a call, similar to other CloudBase calling interfaces, environment initialization needs to be completed.

wx.cloud.init({
env: 'test-x1dzi' // Specify the environment id
})

Node Output

Triggering a workflow through invocation or component behavior allows passing invocation parameters during the call or trigger. The workflow's invocation parameters will serve as the input parameters for this trigger, and the current trigger will output the specific invocation input parameters in the following format:

{
"param":"value" // input parameters
}

Other nodes, expressions, or custom code in the workflow can reference the output output of this trigger node to obtain the workflow's invocation input parameters.

Debugging Instructions

This trigger supports configuring simulated input parameters. The input parameters must be in JSON format. After configuring simulated input parameters, they will be passed as debug input parameters when debugging the workflow or this node.

Note: Invocation method for existing workflows

Note: Currently, due to adjustments in the Cloud Development environment, corresponding Cloud Development environments prefixed with 'lowcode' were previously created, and existing workflows were created in these environments.

For workflows in existing lowcode environments, when using the above invocation method, you must specify the lowcode environment during initialization before invocation; otherwise, an error will occur indicating the workflow cannot be found.

If you do not wish to initialize the lowcode environment, you can use the following invocation method, which will automatically adapt from the cloud development environment to the lowcode environment.

# Initiating Invocation from the Mini Program Client
# Invoking Workflows Using the callFunction Method + Specified Parameters

wx.cloud.callFunction(
"name":"lowcode-wx-datasource", # The name is fixed as lowcode-wx-datasource
"data":{
"action":"StartFlowInstance", # The action is fixed as StartFlowInstance
"actionData":{
"FlowId":"1736582720764907521", # FlowId is the workflow ID, obtained by querying workflow information.
"Params":{ # Invocation parameters, supporting JSON-formatted parameters, which can be obtained via the trigger node's output within the workflow
"hello":"world"
}

}
}
)

The invocation description is as follows:

  • Reuse the callFunction method in Mini Programs or Cloud Functions. Mini Programs or Cloud Functions do not require a base library upgrade.
  • The name parameter for invocation is fixed to lowcode-wx-datasource.
  • In the data input parameters, the action field is fixed to StartFlowInstance
  • Within the data input parameter, inside actionData, FlowId is the workflow ID to be invoked, in the format of a numeric string, which can be obtained by querying workflow information in the workflow list.
  • Within the data input parameter, inside actionData, Params represents the parameters passed to the workflow. The passed parameters can be any content in JSON format and can be obtained via the trigger node's output.

The structure of the returned result after invocation is as follows:

{
"result":{
"code":0,
"data":{
"output":{
"hello":"world"
}
}
}
}

The description of the returned result is as follows:

  • The returned result is in the result structure, which is identical to the cloud function's return result structure.
  • The code indicates the execution status. When it is 0, it indicates that the workflow execution succeeded. If the workflow execution is abnormal, the code value corresponds to a specific error code string.
  • The data contains the execution output, where the output within data represents the workflow's execution output.