Create a Async Task

Setting Up A-Sync Tasks

Creating documents for clients can be a time-consuming process, often involving many steps that don’t require user input. These types of processes are ideal for Async Tasks in WEM.

Whether you're generating documents for all your clients or creating a complex, data-heavy report, Async Tasks allow your application to start the process in the background while the user interface remains responsive.

Preparations

In this example, we’ll use Async Tasks to generate personalized contracts for two distinct client groups. The key requirement is that we want the user to continue using the application while contracts are being created in the background.

The application already contains:

  • A list of clients

  • A list with two contract groups

  • A list of outbound contracts (the tasks resulting documents will appear here)

  • A task tracker list that logs task status and progress

The interface includes:

  • A panel on the left showing currently running and completed tasks. This uses a refresh button inside an interaction node to keep the data up to date.

  • A main panel with client groups already with 2 groups added and a button to start contract processing.

  • A list for the result of our async task where the generated documents are stored.

Creating a Task

Async tasks use the same tasks as scheduled tasks and are found in the tasks folder as part of the navigation tab in the resource pane. When you create or edit an Async Task, you will see a configuration window like the one shown below. This window allows you to define how your task behaves in the runtime.

The name is used as unique identifier and does not allow for spaces, this is because it is also its technical name.

Flowchart property is for the flow that the task will execute. You can drag and drop a flowchart from the resource pane or select one from the list by clicking the flowchart icon. This needs to be an action flowchart ending in a end node


Task Nodes Settings

  • Max Concurrent Task Executions Defines how many instances of this task can run in parallel. For example, setting this to 3 allows three separate instances of this task to run. In this case that would mean making tasks using different templates create contracts at the same time.

  • Max Queue Length The number of task executions that can be waiting in line. If this limit is reached, new start requests will immediately exit via the Queue Full outcome of the Start Task node.

  • Timeout in Minutes If the task hasn’t completed within the specified time, it will automatically stop and receive a timed out status. This helps prevent stuck or endlessly running tasks.

The task used in the Contract Creator example includes an Input folder, which is used to store task-specific data. This folder can be used as a snapshot of the context at the moment the Async Task is started.

Async Tasks are not executed immediately — they are queued and processed in the background. This means that if your task logic pulls data directly from the database, it may be working with outdated or changed information. To avoid inconsistencies and preserve context, it's best practice to pass essential data into the task up front using the input folder.

In this example, the Input folder includes the template to be used for contract generation. By storing this value ahead of time, we ensure that the correct template is always used — even if the template is changed for other uses later while the task is still queued or running.

Starting tasks and retrieving feedback

Async Tasks are triggered from a flowchart within your application — this can be a regular application flow. To start an Async Task, you'll use the Task Node, which can be added by dragging either the generic task node or a specific task from the Tasks folder into your flowchart.

When you drag the task node into a flowchart, you'll be prompted to choose from four different types of task nodes:

  • Start Task – Starts the Async Task and places it into the queue.

  • Stop Task – Attempts to stop the task if it's still in progress.

  • Task Status – Checks the current status of a task instance.

  • Send Feedback – Used within the Async Task itself to send progress updates or messages.

If you drag a specific task (rather than the generic task node), the system will automatically associate the node with that task and prompt you to choose the desired action: Start, Stop, or Task Status.

🧠 Note: The Send Feedback node is only used inside the flowchart used by the Async Task. It's used to update the feedback field with progress indicators, error messages, or any other relevant data you want to pass back to the application.

In the flowchart above, you see the Contract Manager flow. This is the central interaction screen used to manage the contract creation process. It includes several paths that interact with Async Tasks:

  • Start Processing → A flowchart that triggers the Contract_Creator Async Task using the Start Task node.

  • See Progress → Connects to the Get Status node (in this case, Get status:Contract_creator) to retrieve and display the current progress of the task.

  • Reset → Resets the interface or tasks.

  • New Contract Group → Navigates to a different part of the app to create a group or template for other contracts.

The Start Processing path initiates the Async Task, which begins processing contracts in the background. Since the task may take time to complete, we use the Get Status node to let users check on the progress.

In the above image you see the Start Processing flow. This flow creates a task record to store information about this task, and includes the Start task node. Note that there is a Save database node before and after the Start task node — this is needed because the Start task node is executed on the server side. Because of this, we need to make sure that the task record is already saved in the database before the task is started and the id is saved after starting the task. The properties of the task node include the execution ID (where the task ID is stored) and the task input fields. The arguments define which input fields are passed to the task for use during execution — in this example, the template used for generating contracts.

The task can now be started and its progress monitored. The only thing left is the task flow itself, which is defined in a dedicated action flowchart. In this case, the task loops through the contract group and creates a contract for each client. At some point in the flow, feedback should be saved to the database so it can be shown in the application. In the example below, feedback is stored after each contract is created. On the right, the store task feedback properties are shown — the expression sets the feedback message, and the mode determines whether it replaces or appends to the existing value.

The application can now create the PDF contract documents in the background while the user can continue interacting with the application.

Last updated

Was this helpful?