Membership number generator

7
Good day All   I have ran into a bit of a brain breaker and currently out of ideas to solve the problem. Here is the problem.   I have a entity ‘Organization’ and ‘Membership’ with a one to many relationship as many members can belong to one Org. Currently I have a auto number entity on its own that helps generate membership numbers for all the Org’s. Which means membership number is unique in the system.   Now the client wants to change than so that every Org has a membership that starts at one. my system can handle membership number not being unique in the system and just for that Org. But how do I now create the membership numbers for every org when they can have multiple submits at the same time and I dont beleive creating and auto number for every Org is a good idea.   Concurrent execution set to Disallow Yes is not helping me as other people will be trying to submit members over and over until they get a opening. 
asked
2 answers
2

Hi Rick,

As you rightly argued, I don't think AutoNumber are suitable anymore with your requirements. I think you’ll need to manually calculate the membership numbers on membership creation. During membership creation, you can retrieve the last membership (retrieve First Membership associated to the Org sorted by MembershipNumber descending) and add 1 to that number. This way you can maintain separate counters for each Org.

The only issue to be aware of is if requests are handled at the same time, two membership number can have the same membership number. If you want to be absolutely sure of uniqueness, I think you'll have to look into a database lock between retrieval and committing. I’m not too familiar with that myself, but I think this module can help: https://marketplace.mendix.com/link/component/109405

answered
0

Hi Rick,

Have you tried with  Before Commit event on Membership entity?

If not Create an BCo_Microflow and configure that in Membership entity Event Handler.
In that microflow reterive the latest committed object and +1 to the attribute.

 

answered