Creating Workflows
Multiple Queries can be triggered in serial/parallel/conditional when a user interacts with a widget
This document presumes you are familiar with triggering actions from widgets and expands on triggering more complex actions to create a workflow.

Handling Success / Error

The property pane allows us to configure the action to take once a Query returns with a success or an error. Success / Error is determined by the HTTP status code or the query response status returned by the API / Query.
We can decide to display a success or an error message by using the showAlert Action.

Complex Workflows

The GUI is limited to a single onSuccess / onError callback while the underlying framework has no limitation. To write complex workflows that cannot be accommodated in the GUI, click on the JS icon next to the event name & enable JavaScript. Now you can write conditional workflows and chain multiple Queries.
Once you have configured actions using the GUI, you can click on the JS icon next to the event to show the JavaScript equivalent of your configuration. This can help you learn to use JavaScript to configure workflows!

Executing Queries in Parallel / Serial

Every query object contains a run method that is used to execute it. The run method is asynchronous and multiple queries can be executed in parallel as below
1
{{ API1.run(); Query2.run(); API2.run(); }}
Copied!
or chained to be called onSuccess / onError using the callback arguments in the Run Signature
1
{{
2
updateUsers.run()
3
.then(() => fetchUsers.run()
4
.then(() => {
5
showAlert('User Updated');
6
closeModal('Modal1');
7
})
8
.catch(() => showAlert("Fetch Users Failed"))
9
).catch(() => showAlert("Update User Failed", "error"))
10
}}
Copied!

Conditional Execution

Queries can also be chained to execute conditionally based on the value of a widget or the response of a Query
1
{{
2
statusDropdown.selectedOptionValue === "Pending" ?
3
fetchPendingUsers.run(() => {
4
fetchPendingUsers.data.length === 0 ? showAlert("No Users Pending Approval", "info") : showAlert("Fetched Users", "success");
5
}) :
6
fetchApprovedUsers.run();
7
}}
Copied!
Make use of the Appsmith Framework and External Libraries to quickly build logic into your applications
Last modified 13d ago