| description | This page provides detailed information on workflow functions available in Appsmith. |
|---|---|
| title | Workflow Functions |
| hide_title | true |
| toc_min_heading_level | 2 |
| toc_max_heading_level | 3 |
<Tags tags={[ { name: "Business", link: "https://www.appsmith.com/pricing", additionalClass: "business" } ]} />
Workflow functions are in-built framework functions that enables you to interact with different entities like datasources, queries, external systems, and human-in-the-loop interactions. This page provides information about the workflow functions available in Appsmith, including their signatures, parameters, and usage examples.
The executeWorkflow() function serves as a central control unit for executing workflows and marks the starting point of the workflow execution within Appsmith. This function allows you to create a workflow logic for execution of tasks.
```javascript
export default {
async executeWorkflow(data) {
//call a query and read values of parameters
const response = await qs_send_email.run({ "email": data.email });
// Log the response for debugging
console.log(response);
return true;
}
}
```
executeWorkflow(data: JSON): Promise<boolean>Below are the parameters required by the executeWorkflow() function to execute:
```javascript
{
"userId": 123,
"action": "updateProfile",
"data": {
"firstName": "John",
"lastName": "Doe",
"email": "john.doe@example.com"
}
}
```
In your workflow, you can access properties within the data object like userId using dot notation. To access the userId, use data.userId.
The executeWorkflow() returns a Promise that resolves to a boolean value, either true or false, indicating the success or failure of the workflow execution.
The assignRequest() function is an asynchronous function that is part of the workflows object within the global appsmith object in Appsmith. It allows you to create a decision point in a workflow that requires user intervention. This decision point is created as a pending request in the workflow, which can be accessed later in your app to enable users to take action using the Get requests workflow query. Once a pending request is created, the workflow pauses and awaits user action.
async function handleUserRequest() {
try {
await appsmith.workflows.assignRequest({
requestName: "Approval",
resolutions: ["Approved", "Rejected"],
requestToUsers: ["user1", "user2"]
});
console.log("Request successfully assigned and workflow paused.");
} catch (error) {
console.error("An error occurred while assigning the request:", error);
}
}assignRequest({requestName: string, resolutions: string[], requestToUsers: string[], requestToGroups: string[], message: string, metadata:{key: string, value: any}}) : Promise<JSON>Below are the parameters required by the assignRequest() function to execute:
<dd>
The name of the request, which serves as its identifier within the workflow. Give a unique name to the request, and use it to filter requests as part of [Get requests](/workflows/reference/workflow-queries#get-requests) workflow query by adding it in the `Request name` attribute.
</dd>
<dd>
Represents the possible actions a user can take on the request. The applicable resolution passed to the [Resolve requests](/workflows/reference/workflow-queries#resolve-requests) workflow query to apply the selected resolution. For example, `['Approve', 'Reject']`.
</dd>
<dd>
A descriptive message associated with the request, providing more context for users. For example, when creating a refund request, you might include a message like "Refund request raised by User 1".
</dd>
<dd>
Add data that may be needed to process the request or display more information to the user in your app. For example, you can include a unique identifier for the record associated with the request. Use the identifier in your app to fetch and show the details to user.
</dd>
The assignRequest() function returns a Promise in a JSON format representing the generated response. The response includes the following data:
- Debug Workflow - Learn to debug workflows as you build them.