Data trigger
Introduction
There are multiple ways to trigger a workflow in Casewhere. One is data trigger, which allows Casewhere to execute a workflow when data changes.
Imagine your solution must send an email every time a user is added. There are many ways to add a user, and repeating the sending email logic in all user creation workflows is never a good approach. A better one is to create a data trigger that listens to the user creation event and triggers a workflow to send an email.
In Casewhere Admin, navigate to Data Triggers. From here, you can create, edit and manage data triggers like any product resource.

Configuration
The following information is required to configure a data trigger. The data trigger editor groups it in the sections General, Trigger and Workflow.

Name: Name must be required and unique.
Trigger Rule: Rule to determine whether a new workflow should be triggered upon the creation, modification, or deletion of a data object. Here you can learn more about it.
Tracking Data Changes: When enabled, Casewhere compares the data object's attribute values before and after the change and exposes the differences to the trigger rule through the
@diffkeyword.Data Class: The data class the trigger runs on.
Is Synchronous: When checked, the data trigger, including the rule evaluation and workflow execution will run immediately in the same context of the workflow emitting the change event. Otherwise, the data trigger will be queued and executed in the background.
Workflow Definition: The triggered workflow definition will be run when the data object meets the trigger rules. Casewhere only accepts automatic workflow definitions for using with data triggers. The workflow definition must also accept input in order to access the changed data object.
Process: The process Casewhere executes the data trigger. If the workflow definition is case creation, a new case will be created.
Is Active: Based on this value, a trigger can run or not run. If you don't want a trigger to run, uncheck this box.
Priority: Triggers will run in order, so you should set their priority. Priority order: Urgent > As Soon As Possible > Normal > Low.
Delay: The time, in milliseconds, that Casewhere waits before running the workflow. It applies only when Is Synchronous is off, i.e., the workflow runs in the background.
How it works
When a data object changes, Casewhere will examine all active data triggers associated with that data class and execute them in priority order. The workflow can be executed if the data object satisfies the trigger rules. Depending on the configuration, it can be run immediately or in the background.
Let's have a look at an example: a bookstore adds its books with a workflow, and a data trigger makes every new book available for sale.
The workflow DocsWf Add New Book has one step with two form activities: Add New Book and Confirmation Message.

Add New Book shows a form in which the user fills out the Title and the Author of the new book. The form also has a hidden field that sets the Status of the book to "unavailable" when the user saves the form.

Confirmation Message shows the title and the status of the book that was added.
The data trigger DocsWf New Book Trigger runs when a book (a data object of the data class DocsWfBook) is created: its trigger rule is @event.IsCreated. It starts the workflow DocsWf Auto Update Book Status, which sets the Status of the book to "available".

The trigger runs every time a user adds a book. Is Synchronous decides when its workflow changes the status.
If Is Synchronous is checked, the trigger runs the workflow at once, before the user goes on to the next activity, so Confirmation Message already shows the status "available".

Otherwise, the trigger queues the workflow, which runs later in the background. Therefore, Confirmation Message still shows the status the book got from the form: "unavailable".

