Managing a workflow definition from the UI
You can create a workflow from the UI.
About this task
The purpose of the following scenario is to show how to define a Webhook event-driven workflow in the context of an example.
OrdinaryHero is an online store specializing in gym clothes. When a new order is placed, a Webhook notification is sent to the accounting system to confirm payment registration. The Webhook event contains a header named EventType, and the value of the header is NewOrder.
Upon completion of the purchase process, the IT team has developed a script named order_info that automatically sends an email to the warehouse, containing comprehensive order information:
#!/bin/bash
# Email configuration
recipient_email="warehouse@ordinaryhero.com"
subject="New order information"
# Process the webhook data
order_id="12345"
customer_name="Mike Lighthouse"
order_total="$100.00"
customer_address="2570 Lincoln Blvd #101, Venice, California, 90291"
customer_country="USA"
# Construct the email body
email_body="Order ID: $order_id\n"
email_body+="Customer name: $customer_name\n"
email_body+="Order total: $order_total\n"
email_body+="Customer address: $customer_address\n"
email_body+="Customer Country: $customer_country\n"
# Create the email message
email_message="To: $recipient_email\n"
email_message+="Subject: $subject\n"
email_message+="$email_body"
# Send the email using sendmail
echo -e "$email_message" | sendmail -t
The IT team has also defined an event source named
EVT_SRC_ORDERS from the UI. The procedure that
the IT team has followed is described in Managing an event source definition from the UI.The store owner wants to create a workflow that runs order_info script when the payment has been registered, providing order information to the warehouse and initiating the order delivery process. To expedite the process, the owner wants to automate the submission of the workflow upon receiving the Webhook notification.
You can find the steps to automate such process below.
Procedure
-
Create a task template that runs the
order_info script to send emails containing order information to the
warehouse:
- In the Graphical Designer page, select the Assets tab.
- Click Add new and from the drop-down menu, select Task template.
- In the search bar of the Add new task template panel, type "Executable" and select the executable task type.
- In General information, select a Workstation.
- In Folder, select the folder where you want to save the task template.
- In Name, type send_mail_task.
- In Task, select Command from the drop-down menu and enter order_info in the Command or script name field.
- Click Add.
-
Create a workflow that references the send_mail_task
task template:
- From the Blocks tab in the Graphical Designer page, drag a workflow and drop it into the workspace.
- In General information, in Folder, select the folder where you want to save the workflow.
- In Name, type warehouse_order.
- In Workstation, select a workstation.
- From the Assets tab, use the search bar to find the send_mail_task task template, then drag it and drop it into the warehouse_order workflow.
-
Add an event trigger to the warehouse_info
workflow and
define general information about it:
- Select the warehouse_orderworkflow in the workspace.
-
Click on the Add triggers
icon, then click Add new and select
Event trigger from the drop-down menu.
- In General information, in Name, type online_order_trigger.
-
Add a Webhook event condition to the online_order_trigger event
trigger and provide Webhook information:
- In Add new event condition, select Webhook event.
- In Add event panel, select Webhook event received.
- In General information, in Name, type payment_received.
- In Event source, enter EVT_SRC_ORDERS event source.
- In Method, select matches and then select POST from the drop-down menu.
- In Headers, in Key and value, type EventType, NewOrder.
- Deploy the workspace.