Keragon’s Branch logic is a powerful way to control decision flows in your automation. A common scenario is checking if a resource already exists, and based on that, deciding whether to create a new record or update an existing one. This tutorial demonstrates how to achieve this using the Branch logic combined with the Get [Plural] - Search for Records action.
Use Case: Search for a Patient Record, Then Create or Update
Goal
-
Search for a patient by email.
-
If the patient does not exist, create a new patient record.
-
If the patient exists, update the existing record.
Step-by-Step Tutorial
1. Add the Search Action (Get [Plural] — Search for Records)
-
In your workflow editor, click the + icon to add a new step.
-
Select the Patient Management App (or relevant app).
-
Choose the Get Patients (plural) action.
-
Configure the search criteria (e.g., search by email address).
-
Example:
email = {{emailFromJotform}}
📌 Note: This action always returns a list. If the list is empty, no patient was found.
2. Add the Branch Logic
-
Add the Branch logic step immediately after the search action.
-
Rename Branch A to
"Patient does not exist".
Configure the Branch Conditions:
-
Branch A (Create Patient):
-
Value 1: Map to the search action’s output list (e.g.,
Patientsarray). -
Comparison:
is empty -
If the list is empty, proceed to create a new patient.
-
-
Default Branch (Update Patient):
-
This branch is automatically created and doesn’t require additional configuration. If the list is not empty, the workflow will automatically follow this path to update the patient.
-
3. Configure Actions Under Each Branch
-
Branch A (Create Patient):
-
Add a Create Patient action.
-
Fill in the necessary fields to create a new patient record.
-
-
Default Branch (Update Patient):
-
Add an Update Patient action.
-
Use data from the first item in the
Patientsarray to retrieve the patient ID. -
Update the patient’s details as required.
-
4. Test Your Workflow
-
Run a test with an email that doesn’t exist to verify the Create Patient path.
-
Run another test with an existing patient email to verify the Update Patient path.
By combining the Get [Plural] — Search for Records action with Branch logic, you can elegantly handle upsert operations (update if exists, create if not) without complex coding.