How to use Business Events | Mendix 10 (Banner Image)
How to use Business Events | Mendix 10

How to use Business Events | Mendix 10

Mendix With Me
Mendix Community
Published in
7 min readAug 29, 2023

--

In this blog post, I will teach you how to use Business Events in Mendix!

Step by Step

  1. To make this tutorial more accessible, we’ll use the learning path project “Create a Business Event Service in Studio Pro”.
  2. The first project is located in section 3.1.1 called “Get Ready for the First App: Order Management”. Click on “Starter app — OrderManagement” to download
3.1.1 section — “Get Ready for the First App: Order Management”

3. Download the second project on the 4.1.1 section called “Get Ready for the Second App: OrderFulfillment”. Click on “Starter app — OrderFulfillment” to download

4.1.1 section - “Get Ready for the Second App: OrderFulfillment

4. Open an instance of Mendix Studio Pro and click on “Import App Package”. Select the file regarding the first project with the name “Business Events-V10-L3.1.1

Mendix Studio Pro v.10
First Project

5. Choose “New Mendix Team Server” and change the App Name to “BusinessEvents3”

Import App Package with the name “BusinessEvents3

6. After loading the project, right-click on the “OrderManagement” module, go to “Add other” and click on “Business event service

Create a “Business event service

7. Select “Create a new business event service” and change the Document name to “BE_OrderStatusUpdateService

Business event service Popup

8. Click “Add” under the tab “Business event definitions

Business event definitions” tab

9. As a business event write “OrderCancelled

Add a Business Event called “OrderCancelled

10. Add a new attribute

Attributes tab

11. Write as a Name “OrderID” and select “Integer” as a Type

Attribute “OrderID”, type “Integer

12. On step 2, under the tab “Other apps can” select the checkbox “Subscribe to events

Other apps can “Subscribe to events

13. Go to the domain model and check if an entity was created. If yes, all went well.

OrderCancelled Entity

14. Inside the folder “OverviewPages”, click on the “Order_NewEdit” page

Order_NewEdit Page

15. Right-click on the “Save” button and click to go to the microflow

Save Button

16. Drag and drop a retrieve action to the microflow and fill the options with the following information:
Source: From Database
Range: First
XPath: [OrderID = $Order/OrderID]
Object Name: OrderBeforeChange

Retrieve Order Object
Microflow showing retrieve action

17. After the close page action, add a decision and write as a caption “OrderStatus changed to Cancelled”.
For the expression:
$Order/OrderStatus != $OrderBeforeChange/OrderStatus
and
$Order/OrderStatus = OrderManagement.OrderStatus.Cancelled

OrderStatus Decision action
Decision View on the microflow

18. Following the happy way, add a “Create Object” action.
Select as an Entity “OrderCancelled” and add the attribute “OrderID” with the value “$Order/OrderID

Create Object “OrderCancelled

19. On the toolbox search for “Publish business event” and add to your microflow. Double-click on the action and as a Subject write “An order is canceled”. Fill the Business event with the value “$NewOrderCancelled”.

Publish business event” on the toolbox
Publish Business Event Details

20. Before the end event, add a “Log Message” activity.
Log Level: Info
Log node name: ‘OrderManagement”
Template: {1}.{2} is created at {3}
Parameters: {1} — $NewOrderCancelled/ServiceName
{2} — $NewOrderCancelled/EventName
{3} —toString($NewOrderCancelled/createdDate)

Log Message Detail

21. Check if your final microflow is similar to the one in the image below.

Microflow overview

22. Go back to the Business Event and click on the button “Export AsyncAPI Document

Export yaml file
Exported successfully

23. Click on the button “Publish” on the top of Studio Pro

Publish app

24. Open a new instance of Studio Pro and Import a new app Package.
Click on the “Business events — V10 — L4.1.1” file. Create the project with the name “Businessevents4

Second project

25. Right-click on the module “OrderFulfillment” -> Add Other -> Business event service.

Click on new Business Event Service

26. Select “Use an existing business event service”. As a Document name write “BE_OrderStatusUpdateService” and choose the yaml file we just downloaded.

Business Event Service Detail

27. Under the tab Subscribe, click on “Add

Add a button under the Subscribe tab

28. To the business event, select “OrderCancelled”.
Business event entity: “CBE_OrderCancelled”
Handler Microflow: “HandleBE_OrderCancelled”
After clicking “ok”, check on the domain model if the entity was created.

Subscribe Implementation
New OrderCancelled entity created

29. Go to the “HandleBE_OrderCancelled” microflow. Add a retrieve action with the following properties.

Double Click on the Handle microflow
Add a retrieve action

30. Add a Change Object activity. Select as an Object the retrieved object “Shipping”. Change the “ShippingStatus” and fill in the value “OrderFulfillment.ShippingStatus.Cancelled”

Change ShippingStatus to Cancelled
Microflow Overview

31. Click to “Publish” the app.

Publish app

32. Click in View App in both projects to see them on the browser

OrderManagement View
OrderFulfillment

33. On the Manage Customer Orders project, click on new to create a new object.
Order date: Select any date
Total amount: Any amount
Order Status: “Pending” (Can’t be “Cancelled”)

Create a new Order Object

34. Go to the Shipping app and create a new object.
Order ID: It should be the same number of the object created on the Order app
Carrier: Any Carrier
Actual Delivery date: Select any date
Shipping Cost: Any Amount
Shipping Status: “Pending” (Can’t be “Cancelled”)

Create a new Shipping object

35. Return to the Manage Customer Orders project and select the object created. Change the “Order Status” to “Cancelled” and Save.

Modify Order Status

36. Go to the Shipping app and refresh the page. If everything went well, the Shipping Status should be “Cancelled

You’ve made it to the end!

I’m creating a Mendix community on Discord to make life easier for devs. You can ask questions, help other people, and have access to all the tutorials.

If you want to be part of this community, you can do so through this invite.

Discord: https://discord.gg/YHre8dXz3q

Read more

From the writer

If you enjoyed this article you could find more on our Medium page. For great videos, you can visit our YouTube page.

Are you interested in getting more involved with our Discord community? Join us on our Discord Community Channel.

From the Publisher -

Inspired by this article to bring your ideas to life with Mendix? Sign up for a free account! You’ll get instant access to the Mendix Academy, where you can start building your skills.

For more articles like this one, visit our Medium page. And you can find a wealth of instructional videos on our community YouTube page.

Speaking of our community, join us in our Slack community channel. We’d love to hear your ideas and insights!

--

--

Mendix With Me
Mendix Community

Ricardo Pereira: Certified Mendix Expert from Portugal 🇵🇹 | Founder of Mendix With Me community | Join us on Discord: discord.gg/YHre8dXz3q