Can entity event handlers (like BCO, ACO, ...) run in parallel? In case if we have multiple commits at same time.

0
I want to create a custom serial number for every report, which has a format like yyyy-mm-{MonthSerialNumber}. This serial number starts at 1 every month.   So for example, in Jan 2024 serial numbers will be like: 2024-01-1 2024-01-2 ... Feb 2024 serial numbers will be like: 2024-02-1 2024-02-2 ...   I don't want to use AutoNumber, as user has option to cancel/close. AutoNumber keeps on increasing whether the object is comitted or not.   My current approach: 1) Create attribute MonthSerialNumber in the Report entity. 2) Create BCO event handler microflow. 3) In the microflow, I get the last committed report using Retrieve with constraints for fetching only current month's reports and Head list operation. 4) If last comitted report does't exist then MonthSerialNumber for new report is 1. 5) If it exists then MonthSerialNumber for new report is last comitted MonthSerialNumber + 1. 6) Then commit new report without events, and return true.   So my question is when two users create the report at same time, is there a possibility for this event handler microlfow running in paraller or concurrently? Or does Mendix restrict event handler microflows to be run in synchronous manner or on-by-one? Or should I use the default "Disallow concurrent execution" in the event handler microlfow?
asked
3 answers
0

There is a possibility that two users may run this MF at the same time. Disallowing concurrent execution fixes this problem, but it will block one of your users, which I guess is an undesired behavior.

 

Alternatively, you could use a non-persistent entity (with duplicated attributes) to fill in the form and create a persistent object with an autonumber after committing the object. This prevents the autonumber from increasing when canceled.

answered
0

In that case, it is agreed that AutoNumber is not an option.

Another solution (if there is no need to display the MonthSerialNumber to the user immediately after creating the report) is to set the MonthSerialNumber afterwards in a scheduled event. (Retrieve all reports sorted by CreatedDate and set MonthSerialNumber)

answered
0

Hi,

you will need to implement some locking mechanism for the number generation part - e,g, something like in this module https://marketplace.mendix.com/link/component/109405

regards, Fabian

answered