<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Andreas Blaesius on Medium]]></title>
        <description><![CDATA[Stories by Andreas Blaesius on Medium]]></description>
        <link>https://medium.com/@gandy84?source=rss-abaa26e23bd6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*-1tvVedxGOX2j1pSlKLDQw.jpeg</url>
            <title>Stories by Andreas Blaesius on Medium</title>
            <link>https://medium.com/@gandy84?source=rss-abaa26e23bd6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 22:12:26 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@gandy84/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Comparing Strings in DB or Runtime? There is a Difference — Mendix and Me]]></title>
            <link>https://medium.com/mendix/comparing-strings-in-db-or-runtime-there-is-a-difference-mendix-and-me-2a7f6ad85e0d?source=rss-abaa26e23bd6------2</link>
            <guid isPermaLink="false">https://medium.com/p/2a7f6ad85e0d</guid>
            <category><![CDATA[low-code]]></category>
            <category><![CDATA[mendix]]></category>
            <category><![CDATA[string-operations]]></category>
            <category><![CDATA[how-to]]></category>
            <category><![CDATA[database]]></category>
            <dc:creator><![CDATA[Andreas Blaesius]]></dc:creator>
            <pubDate>Fri, 13 Oct 2023 09:02:10 GMT</pubDate>
            <atom:updated>2024-01-12T12:05:49.572Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Comparing Strings in DB or Runtime? There is a Difference — Mendix and Me (Banner Image)" src="https://cdn-images-1.medium.com/max/1024/1*jIa13qXJ2t6lnYSSGgC-6Q.png" /><figcaption>Comparing Strings in DB or Runtime? There is a Difference — Mendix and Me</figcaption></figure><h3>Comparing Strings in DB or Runtime? There is a Difference — Mendix and Me</h3><p>You may already know my post about different database behavior when it comes to strings. If not, you can find it here:</p><p><a href="https://medium.com/mendix/database-database-mendix-and-me-e9d54c63fb23">Database != Database — Mendix and Me</a></p><p>The short version is: It depends on the database you are using if a statement like [String = ‘ABC’] is case sensitive or not. Postgresql is case-sensitive, but the Mendix built-in database is not. I just stumbled across a new example that adds to this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/489/1*ydLiE36Fe7swgStRQ2Ge9Q.png" /></figure><h4><strong>Comparing Strings using contains — A New Hope</strong></h4><p>Depending on the amount of objects in your database, using contains in an XPath query will solve the problem of the different behavior. In a database context, contains is always case insensitive. If you translate the statement above to [contains(String, ‘ABC’)] it will return every object that has ‘ABC’, no matter if it is upper or lower case.</p><p>Ok, this will only work if a contains search is what you need. But this is a different topic. What I want to talk about is the different behavior between a database retrieve and filtering in a microflow.</p><h4><strong>Expectation vs. Reality</strong></h4><p>Let’s compare two different scenarios. I created a test app to demonstrate that. The domain model is simple. It has a persistable entity with a string and a non-persistable entity with a search string.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/250/1*KAbQY_0J8Q3hXW0AiO1Xow.png" /></figure><p>I created a page that shows the search string and a data grid with a list of entity objects.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YeTze14im7_NGw--zQHJ9w.png" /></figure><p>Entering a search string triggers a microflow that performs three different retrieves/filterings and counts the result list. Let’s look at them one by one.</p><p>The first action is a database retrieve with the following XPath constraint:</p><pre>[contains(StringAttribute, $SearchHelper/Searchstring)]</pre><p>The second one is retrieving all objects from the database and then performing a filter by expression action on that list. The expression looks like this:</p><pre>contains($currentObject/StringAttribute, $SearchHelper/Searchstring)</pre><p>What is your expectation? Are both actions returning the same amount of objects? I thought they should do but I guess it’s no surprise for you if I now tell you: They don’t.</p><p>As mentioned before, using contains in a database context is case insensitive. But using it in runtime (for example in a filter action) is case-sensitive. I was testing it with a list of two objects. One object had the string ‘Test’ the other had the string ‘test’. Searching for ‘test’ had two results when searching on the database, but only one result when filtering in a microflow. The microflow action is case-sensitive.</p><p><strong>The solution</strong></p><p>As mentioned before, there is a third option. It has a simple solution to make the microflow filter action behave like the database. At runtime you can force the system to only compare lower case strings (Or upper case, if you prefer that). The filter expression needs to look like this:</p><pre>contains(toLowerCase($currentObject/StringAttribute), toLowerCase($SearchHelper/Searchstring))</pre><p>This will ensure that you compare lowercase characters to lowercase characters and will result in the same amount of objects as if you would do it on the database. Not very intuitive at first sight, but now that I know that, it can be useful to use both options.</p><p>As always, I am happy to receive your feedback and input.</p><h4>Read more</h4><ul><li><a href="https://docs.mendix.com/refguide/string-function-calls/">String Function Calls</a></li><li><a href="https://docs.mendix.com/refguide/expressions/">Expressions</a></li></ul><p><strong><em>From the Publisher -</em></strong></p><p>Inspired by this article to bring your ideas to life with Mendix? Sign up for a <a href="https://signup.mendix.com/?utm_medium=content_syndication&amp;utm_source=medium.com&amp;utm_id=11172331">free account</a>! You’ll get instant access to the <a href="https://academy.mendix.com/link/home">Mendix Academy,</a> where you can start building your skills.</p><p>For more articles like this one, visit our <a href="https://medium.com/mendix">Medium page</a>. And you can find a wealth of instructional videos on our <a href="https://www.youtube.com/c/MendixCommunity/community">community YouTube page</a>.</p><p>Speaking of our community, join us in our <a href="https://join.slack.com/t/mendixcommunity/shared_invite/zt-hwhwkcxu-~59ywyjqHlUHXmrw5heqpQ">Slack community channel</a>. We’d love to hear your ideas and insights!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2a7f6ad85e0d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mendix/comparing-strings-in-db-or-runtime-there-is-a-difference-mendix-and-me-2a7f6ad85e0d">Comparing Strings in DB or Runtime? There is a Difference — Mendix and Me</a> was originally published in <a href="https://medium.com/mendix">Mendix Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Module rolls? A difficult decision — Mendix and Me]]></title>
            <link>https://medium.com/mendix/module-rolls-a-difficult-decision-mendix-and-me-aee0e489f78b?source=rss-abaa26e23bd6------2</link>
            <guid isPermaLink="false">https://medium.com/p/aee0e489f78b</guid>
            <category><![CDATA[security]]></category>
            <category><![CDATA[architecture]]></category>
            <category><![CDATA[low-code]]></category>
            <category><![CDATA[tips]]></category>
            <category><![CDATA[mendix]]></category>
            <dc:creator><![CDATA[Andreas Blaesius]]></dc:creator>
            <pubDate>Mon, 08 May 2023 07:29:19 GMT</pubDate>
            <atom:updated>2023-06-22T12:34:56.406Z</atom:updated>
            <content:encoded><![CDATA[<h3>Module rolls? A difficult decision — Mendix and Me</h3><h4>This article will deal with the interaction between project roles and module roles in Mendix applications. A topic that seems quite obvious at first glance, but can drive even experienced developers to despair. But let’s start from the beginning.</h4><figure><img alt="Module rolls? A difficult decision — Mendix and Me Banner Image: 3 padlocks interconnected" src="https://cdn-images-1.medium.com/max/1024/1*NgkLJkPDzq7ksrWfQ6Ug8g.png" /><figcaption>Module rolls? A difficult decision — Mendix and Me</figcaption></figure><h3>What are project roles and module roles?</h3><p>A project role is the user role assigned to a user. This role is carried by the user throughout the application. Module roles, however, refer only to a single module and are not assigned directly to users. So a user himself has no module role or is only indirectly assigned to them.</p><p>The relationship between the user and the module role comes from the fact that the project roles can be assigned to module roles. This way a user also gets the right to do things in a certain module, to read, to write,…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/829/0*v6Lj7yHtg5gjr9il.png" /></figure><h3>Wouldn’t it be easier to just have project roles?</h3><p>At first glance, it may seem that the interaction between the module roles and project roles adds unnecessary complexity to the application. In practice, however, this creates many advantages. The biggest advantages are that it allows you to reuse a module in other applications and that you can make rights management within a module simple, even if it is complex throughout the application. This makes development easier.</p><h3>So what’s the problem now?</h3><p>There are a few pitfalls when creating module roles that may require consideration. I would like to go into this with the help of a (very artificial) example project.</p><p>Let’s take a look at an application for managing employees within a company. Our application collects a lot of information about our employees such as first name, last name, monthly salary, start of employment, and a satisfaction index. The application is accessed by different people who have different roles in the application. The most significant ones are Accounting, HR, and OfficeFun.</p><p>Accounting is primarily concerned with employee pay. One piece of information that Accounting is not allowed to see—for privacy reasons—is the satisfaction index of our employees. HR is the role that is allowed to see both contractual and satisfaction scores. OfficeFun individuals are allowed to see employee satisfaction but are not allowed to access their salary information.</p><p>So essentially we now have two visibilities. One of them controls the visibility of the salary data, the other one controls the visibility of the satisfaction index. From the module point of view, it is obvious to work with two roles that are not directly related to the project roles. If you look at common and well-known modules, this is often exactly how they work. Here, for example, the MxModelReflection:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*bE3RTA56-TIDJqbu.png" /></figure><p>Here, a distinction is made between the administrator of the module and all other users who want to have read access to it. In the case of MxModelReflection, this is the only logical approach. It is a marketplace module that is used in a large number of applications.</p><p>With this information, it is obvious—as already mentioned—to give our module exactly two module roles. The whole thing would then look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/801/0*xplEgGp6oiYs_7sj.png" /></figure><p>The assignment to the project roles would look as follows in our example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/850/0*D41eUWZBcTiD-6Ic.png" /></figure><p>Accounting has the FinancialView module role, HR has the FinancialView and SatisfactionView module roles, and OfficeFun only has the SatisfactionView module role.</p><p>From the level of access rights, everything is thus clarified and works as it should. So what is still at stake here?</p><p>Let’s imagine that there is a requirement to integrate certain views into the dashboard of the application, which is the same for everyone. Accounting should get an overview in which all employees are listed with their salaries. OfficeFun should have a similar view but with the satisfaction index. We can solve this quite easily by placing multiple views on the page and using visibility constraints to show and hide them. The module roles can be used for this.</p><p>When an accounting employee logs in, the following view is displayed:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*4avgl6lihD9gy1w7.png" /></figure><p>An Office Fun employee would see this view:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*mYdIJ_Qn7Kj37ymt.png" /></figure><p>However, a problem will arise when someone from HR logs into the application. Since HR is assigned to both module roles, this results in a duplicated view:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_FiWnnM9lIYP8vO5.png" /></figure><p>Of course, this is a very contrived, artificial case. But problems of exactly this kind are regularly found in very many projects. If the application has been in development for a while or is maybe even live, it is difficult to rebuild all the roles again to apply changes. Getting the visibility under control now, unfortunately, requires a lot of effort for a developer (different pages per role, helper objects to control the visibility, etc).</p><h3>What does this mean for my applications now?</h3><p>When it comes to deciding how to design your module roles, you should essentially distinguish between two types of modules.</p><ol><li>Generic modules that have little or no integration into the application in terms of content and that can be reused relatively easily in other applications.</li><li>Modules that are highly integrated into the application in terms of content and are unlikely to be reused in other applications.</li></ol><p>In the case of the first modules (Marketplace modules such as MxModelReflection or XLS Report are usually used as examples here), it is advisable to do without interlocking between project roles and module roles in order to simplify reusability. Ideally, the module roles have no direct relation to the project roles and rather have names like “Admin” or “User.”</p><p>In the second case, it usually makes more sense if the module roles correspond exactly to the project roles. This way it can avoid issues like several module roles assigned to one project role. This makes it easier to avoid problems like the one described above, but it can also improve the performance of the application. If you have complicated XPATH constraints in the domain model, then in the case of multiple module roles per project role, all role-specific constraints must also be applied. In the case of a 1-to-1 assignment, however, only the constraints of one role must be evaluated.</p><h3>Conclusion?!?</h3><p>Even if at first glance it may mean more effort to create a module role per project role, this can pay off at a later point in time and avoid many problems. Changes to requirements especially can be implemented more easily, but also performance can benefit from such a design.</p><p>On the other hand, “non-specific” modules can be exported and reused much more easily if they are connected as little as possible (ideally not at all) with the actual project.</p><p>So, on the whole, the old advice: Think first, then build! 🤣</p><p>I hope this was interesting for anyone reading this. As always I am happy about your feedback.</p><p><em>Originally published in the German language at </em><a href="https://mendixandme.de/index.php/2023/05/08/modulrollen-schwierige-entscheidung/"><em>https://mendixandme.de</em></a><em> on May 8, 2023.</em></p><h4>Read more</h4><ul><li><a href="https://docs.mendix.com/refguide7/user-roles/">User Roles</a></li><li><a href="https://docs.mendix.com/refguide7/security/">Security</a></li></ul><p><strong><em>From the Publisher -</em></strong></p><p><em>If you enjoyed this article you can find more on our </em><a href="https://medium.com/mendix"><em>Medium page</em></a><em>. For great videos and live sessions, you can visit our library of </em><a href="https://www.mendix.com/videos/"><em>on-demand videos</em></a><em> or our community </em><a href="https://www.youtube.com/c/MendixCommunity/community"><em>Youtube page</em></a><em>.</em></p><p><em>For the makers looking to get started, you can sign up for a </em><a href="https://signup.mendix.com/link/signup/?source=direct"><em>free account</em></a><em>, and get instant access to learning with our </em><a href="https://academy.mendix.com/link/home"><em>Academy</em></a><em>.</em></p><p><em>Are you interested in getting more involved with our community? Join us in our </em><a href="https://join.slack.com/t/mendixcommunity/shared_invite/zt-hwhwkcxu-~59ywyjqHlUHXmrw5heqpQ"><em>Slack community channel</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aee0e489f78b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mendix/module-rolls-a-difficult-decision-mendix-and-me-aee0e489f78b">Module rolls? A difficult decision — Mendix and Me</a> was originally published in <a href="https://medium.com/mendix">Mendix Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Scheduled Events and Queue Processing- Mendix and Me]]></title>
            <link>https://medium.com/expsoftwareengineering/scheduled-events-and-queue-processing-mendix-and-me-6f4421a4ee5b?source=rss-abaa26e23bd6------2</link>
            <guid isPermaLink="false">https://medium.com/p/6f4421a4ee5b</guid>
            <category><![CDATA[low-code]]></category>
            <category><![CDATA[queue]]></category>
            <category><![CDATA[scheduled-event]]></category>
            <category><![CDATA[mendix]]></category>
            <dc:creator><![CDATA[Andreas Blaesius]]></dc:creator>
            <pubDate>Fri, 23 Dec 2022 06:54:06 GMT</pubDate>
            <atom:updated>2022-12-23T19:41:24.975Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/829/0*eaYpM77eGv0GVeYU.png" /></figure><p>Okay, this case doesn’t come up very often. However, when it does, it can have problematic consequences. If it happens in a production environment, it can cause the production environment to stop.</p><p><strong>The Usecase</strong></p><p>Running processes in a queue (I use the term queue in the following for all kinds of queues in Mendix. Process Queue, Task Queue,…) is something very useful. On the one hand you can move long running processes to the background and give the user a smoother experience, on the other hand you can create batch processing to split large actions (data migrations, regular synchronizations,…) into small work packages. This way you can make sure that the transaction doesn’t get too big (which can lead to problems up to a system crash).</p><p><strong>What does this have to do with Scheduled Events?</strong></p><p>A specific use case that I have encountered several times is a data synchronization that runs regularly in the background. Our application needs to retrieve data from an API at a certain interval and then process it locally. This processing should be done in work packages for the reasons mentioned above. If you have already dealt with the queue the solution is obvious. A Scheduled Event retrieves data from the API at fixed intervals, creates work packages and then processes them in the queue.</p><p>This is probably the ultimate solution and there is nothing you should do “differently”. A typical microflow for the Scheduled Event looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*j9PwyKUaHGOb4z_Y.png" /></figure><p>First we import data, then we create work packages and finally we execute the processing of them in the queue.</p><p><strong>But why do you write a blog article about it?</strong></p><p>Well, what makes a Scheduled Event is also what can cause problems with a Scheduled Event: It repeats periodically.</p><p>This is normally exactly the behavior we want to create with a Scheduled Event. It should run every X seconds/minutes/hours/days/…. But what if the execution of the Scheduled Event takes longer than the period in which it is executed?</p><p><strong>The standard case</strong></p><p>Mendix has of course already thought about the above problem and established a mechanism to address it. When you create a scheduled event you can define how it should behave in this case.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/962/0*SWp1CZ-4pG3HooKD.png" /></figure><p>The “On overlap” setting lets us define how the event should behave when the execution time exceeds the period. You can choose whether the next execution of the event should be skipped or delayed. If you choose “Skip next”, no event will be executed until the execution of the current event is finished. After that it continues with the normal period. If you choose Delay, the following executions will be delayed. They are put into a kind of queue and processed as soon as the first execution is finished (this also has certain risks, but that is not the point here).</p><p><strong>What about the queue now?</strong></p><p>If work packages are created within the Scheduled Event and are processed in a queue, it is no longer possible for the event to know whether everything has already been processed or not. It can only decide whether the creation of the work packages has been completed. If the actual processing of the packages now takes longer than the period between two executions of the event, then with each execution more and more work packages are put into the queue. The pile of work grows continuously and is never processed.</p><p>This problem cannot be solved with the default Scheduled Event configuration. Yes, you can choose a larger period as a precaution. But things are first of all not always so predictable and users probably want a data synchronization as soon as possible.</p><p><strong>What to do?</strong></p><p>To avoid the problems mentioned above, we need to manually recreate what the Scheduled Event normally does automatically in the microflow. We have to find out if the previous execution is already finished or not. To do this, we give our batch object an attribute that serves as an indicator of whether the processing has already been completed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/305/0*MhEscPfiCKeLDFPl.png" /></figure><p>In its most simplistic form, this is simply a Boolean attribute. When the batch is created, the attribute is set to false, after the processing has finished, we set it to true. To our microflow presented above we introduce a database query that checks if there are still batches that are not executed. The whole thing looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*unwwEXceri9GlPpG.png" /></figure><p>We first count if there are still batches that are not processed. If there are none left, we execute the microflow we used in the first example. In the actual execution in the queue we have to set the Finished attribute of course.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*zCmWXIMbnN7EA2ke.png" /></figure><p>Now we have recreated the “skip next” behavior for use with the queue in a very simple way and no longer run the risk of overflowing the queue with events executed too frequently.</p><p><strong>But what about „Delay next”?</strong></p><p>Even if I would advise against Delay next in most cases, I would like to introduce a Delay Next variant for the sake of completeness. For this we have to build a loop into our Scheduled Event Microflow in which we check again and again if the previous processing is finished. I strongly recommend to work with a delay because otherwise the database queries are executed one after the other until the desired result appears. This can put an enormous load on the system. In the <a href="https://marketplace.mendix.com/link/component/170">Community Commons</a> there is a Java action called Delay that does just that for us. It makes the system wait.</p><p>Armed with this delay and the loop, our event microflow now looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*uWou-A6Ienk2Mn_k.png" /></figure><p>Instead of aborting the execution, the database is checked again and again until there is no more batch that has not yet been processed. As soon as this is the case, the actual logic of the event is executed. Thus both behaviors of the event could be extended to the queue with simple means and we can prevent that the queue is overloaded by too many event executions</p><p>Of course, you don’t need that for every event. It is a small special case. But whenever you run an event very often and possibly process a lot of data you should think about implementing such a mechanism. It can be implemented quickly and may save you from serious problems.</p><p>I hope this was interesting for one or the other. As always, I am happy about feedback and comments.</p><p><em>Originally published at </em><a href="https://medium.com/mendix/scheduled-events-and-queue-processing-mendix-and-me-16e9bd3776b3"><em>https://gandy84.medium.com</em></a><em> on December 23, 2022.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6f4421a4ee5b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/expsoftwareengineering/scheduled-events-and-queue-processing-mendix-and-me-6f4421a4ee5b">Scheduled Events and Queue Processing- Mendix and Me</a> was originally published in <a href="https://medium.com/expsoftwareengineering">eXpSoftwareEngineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Scheduled Events and Queue Processing— Mendix and Me]]></title>
            <link>https://medium.com/mendix/scheduled-events-and-queue-processing-mendix-and-me-16e9bd3776b3?source=rss-abaa26e23bd6------2</link>
            <guid isPermaLink="false">https://medium.com/p/16e9bd3776b3</guid>
            <category><![CDATA[scheduled-event]]></category>
            <category><![CDATA[mendix]]></category>
            <category><![CDATA[tips]]></category>
            <category><![CDATA[how-to]]></category>
            <category><![CDATA[queue]]></category>
            <dc:creator><![CDATA[Andreas Blaesius]]></dc:creator>
            <pubDate>Fri, 23 Dec 2022 06:37:52 GMT</pubDate>
            <atom:updated>2023-02-16T10:23:31.799Z</atom:updated>
            <content:encoded><![CDATA[<h4>Okay, this case doesn’t come up very often. However, when it does, it can have problematic consequences. If it happens in a production environment, it can cause the production environment to stop.</h4><figure><img alt="Scheduled Events and Queue Processing- Mendix and Me (Banner Image)" src="https://cdn-images-1.medium.com/max/1024/1*lYIDkQ6fYSI9VcJ8WDHMog.png" /><figcaption>Scheduled Events and Queue Processing — Mendix and Me</figcaption></figure><h4><strong>The Usecase</strong></h4><p>Running processes in a queue (I use the term queue in the following for all kinds of queues in Mendix. I use it to refer to both Process Queues, and Task Queues) is something very useful. On the one hand, you can move long-running processes to the background and give the user a smoother experience, on the other hand, you can create batch processing to split large actions (data migrations, regular synchronizations,…) into small work packages. This way you can make sure that the transaction doesn’t get too big (which can lead to problems up to a system crash).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/829/1*iqX8dZoGdHtZaEc_3iVmBA.png" /></figure><h4><strong>What does this have to do with Scheduled Events?</strong></h4><p>A specific use case that I have encountered several times is a data synchronization that runs regularly in the background. Our application needs to retrieve data from an API at a certain interval and then process it locally. This processing should be done in work packages for the reasons mentioned above. If you have already dealt with the queue the solution is obvious. A Scheduled Event retrieves data from the API at fixed intervals, creates work packages, and then processes them in the queue.</p><p>This is probably the ultimate solution and there is nothing you should do “differently”. A typical microflow for the Scheduled Event looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*pqniLF9RqWE0cAgA.png" /></figure><p>First, we import data, then we create work packages and finally we execute the processing of them in the queue.</p><h4><strong>But why do you write a blog article about it?</strong></h4><p>Well, what makes a Scheduled Event is also what can cause problems with a Scheduled Event: It repeats periodically.</p><p>This is normally exactly the behavior we want to create with a Scheduled Event. It should run every X seconds/minutes/hours/days/…. But what if the execution of the Scheduled Event takes longer than the period in which it is executed?</p><h4><strong>The standard case</strong></h4><p>Mendix has of course already thought about the above problem and established a mechanism to address it. When you create a scheduled event you can define how it should behave in this case.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/962/0*EmWjutUkArHsfJFl.png" /></figure><blockquote>The “On overlap” setting lets us define how the event should behave when the execution time exceeds the period. You can choose whether the next execution of the event should be skipped or delayed.</blockquote><p>If you choose “Skip next”, no event will be executed until the execution of the current event is finished. After that, it continues with the normal period. If you choose Delay, the following executions will be delayed. They are put into a kind of queue and processed as soon as the first execution is finished (this also has certain risks, but that is not the point here).</p><h4><strong>What about the queue now?</strong></h4><p>If work packages are created within the Scheduled Event and are processed in a queue, it is no longer possible for the event to know whether everything has already been processed or not. It can only decide whether the creation of the work packages has been completed. If the actual processing of the packages now takes longer than the period between two executions of the event, then with each execution more and more work packages are put into the queue. The pile of work grows continuously and is never processed.</p><p>This problem cannot be solved with the default Scheduled Event configuration. Yes, you can choose a larger period as a precaution. But things are first of all not always so predictable and users probably want data synchronization as soon as possible.</p><h4><strong>What to do?</strong></h4><p>To avoid the problems mentioned above, we need to manually recreate what the Scheduled Event normally does automatically in the microflow. We have to find out if the previous execution is already finished or not. To do this, we give our batch object an attribute that serves as an indicator of whether the processing has already been completed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/305/0*L8uofea7TyvfVQfK.png" /></figure><p>In its most simplistic form, this is simply a Boolean attribute. When the batch is created, the attribute is set to false, after the processing has finished, we set it to true. To our microflow presented above we introduce a database query that checks if there are still batches that are not executed. The whole thing looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*BfW7bTT5jeWUy0JW.png" /></figure><p>We first count if there are still batches that are not processed. If there are none left, we execute the microflow we used in the first example. In the actual execution in the queue, we have to set the Finished attribute of course.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Ese0AwDv5Uv21Pz3.png" /></figure><p>Now we have recreated the “skip next” behavior for use with the queue in a very simple way and no longer run the risk of overflowing the queue with events executed too frequently.</p><h4><strong>But what about ”Delay next”?</strong></h4><p>Even if I would advise against Delay next in most cases, I would like to introduce a Delay Next variant for the sake of completeness. For this, we have to build a loop into our Scheduled Event Microflow in which we check again and again if the previous processing is finished. I strongly recommend working with a delay because otherwise the database queries are executed one after the other until the desired result appears. This can put an enormous load on the system. In the <a href="https://marketplace.mendix.com/link/component/170">Community Commons</a>, there is a Java action called Delay that does just that for us. It makes the system wait.</p><p>Armed with this delay and the loop, our event microflow now looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*e-br4dVq7yCIuh4E.png" /></figure><p>Instead of aborting the execution, the database is checked again and again until there is no more batch that has not yet been processed. As soon as this is the case, the actual logic of the event is executed. Thus both behaviors of the event could be extended to the queue with simple means and we can prevent the queue from becoming overloaded by too many event executions</p><p>Of course, you don’t need that for every event. It is a small special case. But whenever you run an event very often and possibly process a lot of data you should think about implementing such a mechanism. It can be implemented quickly and may save you from serious problems.</p><p>I hope this was interesting for one or the other. As always, I am happy about feedback and comments.</p><p><em>Originally published in german language at </em><a href="https://mendixandme.de/index.php/2022/12/23/scheduled-events-und-queue-prozesse/"><em>https://mendixandme.de</em></a><em> on December 23, 2022.</em></p><h4>Read more</h4><ul><li><a href="https://docs.mendix.com/refguide/scheduled-events/">Scheduled Events</a></li><li><a href="https://docs.mendix.com/refguide/task-queue/">Task Queue</a></li><li><a href="https://docs.mendix.com/refguide/retrieve/#332-range">Retrieve</a></li></ul><p><em>From the Publisher -</em></p><p><em>If you enjoyed this article you can find more like it on our </em><a href="https://medium.com/mendix"><em>Medium page</em></a><em>. For great videos and live sessions, you can go to </em><a href="https://www.mendix.com/live/"><em>MxLive</em></a><em> or our community </em><a href="https://www.youtube.com/c/MendixCommunity/community"><em>Youtube pag</em></a><em>e.</em></p><p><em>For the makers looking to get started, you can sign up for a </em><a href="https://signup.mendix.com/link/signup/?source=direct"><em>free account</em></a><em>, and get instant access to learning with our </em><a href="https://academy.mendix.com/link/home"><em>Academy</em></a><em>.</em></p><p><em>Interested in getting more involved with our community? Join us in our </em><a href="https://join.slack.com/t/mendixcommunity/shared_invite/zt-hwhwkcxu-~59ywyjqHlUHXmrw5heqpQ"><em>Slack community channel</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=16e9bd3776b3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mendix/scheduled-events-and-queue-processing-mendix-and-me-16e9bd3776b3">Scheduled Events and Queue Processing— Mendix and Me</a> was originally published in <a href="https://medium.com/mendix">Mendix Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mendix, ‘nice gimmick’ or the evolution of code? — Mendix and Me]]></title>
            <link>https://medium.com/mendix/mendix-cant-be-taken-seriously-right-mendix-and-me-f0a90fa2c5ff?source=rss-abaa26e23bd6------2</link>
            <guid isPermaLink="false">https://medium.com/p/f0a90fa2c5ff</guid>
            <category><![CDATA[low-code]]></category>
            <category><![CDATA[mendix]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Andreas Blaesius]]></dc:creator>
            <pubDate>Fri, 18 Feb 2022 13:47:03 GMT</pubDate>
            <atom:updated>2022-03-10T10:26:25.479Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Mendix, ‘nice gimmick’ or the evolution of code? — Mendix and Me" src="https://cdn-images-1.medium.com/max/1024/1*59_CVbtT2ZzP2k9KdmaZYQ.png" /><figcaption>Mendix, ‘nice gimmick’ or the evolution of code? — Mendix and Me</figcaption></figure><h3>Mendix, ‘nice gimmick’ or the evolution of code? — Mendix and Me</h3><h3>One thing I’ve noticed ever since I started working with Mendix is how differently people react when you tell them you’re doing LowCode development with Mendix. Usually, there are three types of reactions:</h3><figure><img alt="Mendix and Me — Just another Mendix blog" src="https://cdn-images-1.medium.com/max/1024/1*zFUtZRR75jS5bkeLqAY9MA.png" /><figcaption>Mendix and Me — Just another Mendix blog</figcaption></figure><ol><li><strong>The other Mendix/LowCode developer</strong><br>Other Mendix developers are familiar with the matter. They know what I am talking about when I talk about Mendix and LowCode. The reactions are accordingly predictable.</li><li><strong>People without a development background</strong><br>People who have no experience with software development are usually not interested in the technology, but rather in the solutions. They don’t care at first how a problem is solved, as long as it is solved in their sense.</li><li><strong>The High Code developer</strong><br>High Code developers are “real” developers. They have learned to develop with programming languages such as C, Java, Python, JavaScript,… (the list can be extended endlessly). If you tell a high code developer about Mendix, the reaction is often initially negative.</li></ol><p>Well, I know that I am playing with stereotypes here and that of course not all people are the same. There are intersections between the groups and of course, there are also completely different reactions. But this is not meant to be a sociological essay. I want to use these stereotypes to address something else. Here I am particularly interested in high code developers and people without development experience.</p><h3>Mendix is an evolutionary step</h3><p>Something that I observe again and again, and that I observed with myself at the beginning of my work with Mendix, is the division into “real programming” (high code programming languages) and “nice gimmick” (low code programming languages). I myself was not free of prejudice. My first impression of Mendix was that it is a nice tool to build small applications and mockups. But nothing more.</p><p>How wrong I was.</p><p>After years of working with Mendix, I see it as the logical next step in the way we developers interact with computers. To explain this I need to go back a few years. The following will not be an encyclopedia of computer history and does not claim to be complete, but I want to talk briefly about how software development has changed.</p><h3>The evolution of computer programming</h3><p>There are two things you can say about computers.</p><ol><li>Computers are stupid</li><li>Modern computers (with the exception of quantum computers) basically work according to the same principle as computers in the 60s (or before).</li></ol><p>To program a computer you have to give it commands. These commands must be available to the computer in binary form. This is of course a very painstaking and time-consuming procedure. The handling of a computer in binary code is only accessible to a few specialists. It is obvious that a more practical solution was necessary.</p><p>The next step of evolution is represented by assembly languages. Each processor type has its own instruction set that can be represented in an assembler. This language is easier to read for humans and so it is easier to develop in it. Assembler is therefore an abstraction layer that hides the binary code from humans. However, anyone who has worked with assembly languages knows that this is also very tedious. Basic comfort functions of more modern languages are missing and have to be developed anew every time. In addition, a program must be rewritten if you want to run it on a new processor type because another processor type brings a different assembler instruction set.</p><p>The solution to these inconveniences is higher (high code) programming languages. Popular examples are C, Java, and JavaScript. These languages have the advantage that their syntax is even more oriented to human readability, they bring convenience features like loops, they take care of memory management and by using compilers or interpreters the programs developed in them are portable. These languages are a further abstraction layer that hides the complexity of binary code or assembler from the developer.</p><p>But of course, the use of high code languages also has its disadvantages. A developer loses direct control over the processes in the computer. The syntax of the language summarizes commands of the machine language in such a way that easy-to-use actions become from it (At the latest here the Mendix developers among my readers should notice what I want to go for 😉).</p><p>This loss of direct control is the price you pay to get to the desired result faster and to make the language accessible to a larger group of developers.</p><h3>But what does all this have to do with Mendix?</h3><p>The criticism one often hears is that with Mendix one would not have direct control over the code and that the reduction to a few actions is a limitation. However, if you look at the evolution of programming languages, you will see that these arguments are as old as computers themselves.</p><p>Mendix and LowCode are the next steps in the evolution. Mendix is another abstraction layer that hides the complexity of high code, assembler, and machine language from the developer. The developer gives up a part of his direct control but is thereby able to develop applications faster. In addition, the development environment is now more accessible for a larger group of developers.</p><p>Do you notice anything? Exactly. It’s the exact same arguments that were in favor of high code that is now in favor of low code. Each evolutionary step has resulted in an improvement of the development speed and a democratization of the development process.</p><h3>What is the best solution at this time?</h3><p>The answer to this question is simple: there is no single best solution. The existence of Mendix does not make the use of high Code obsolete. High code has its place in many areas (like how Mendix can be extended with Java and JavaScript). Likewise, there are still areas where assembler and machine code are the tools of choice. However, it must be recognized that LowCode is the consequence of an evolution that will probably go on and on.</p><p>So, just give it a try. If you are already a Mendix developer, I don’t have to tell you all this. If not, give it a try. Don’t just look at the limitations, but look at the possibilities it opens up. Just as it has always been in the evolution of software development.</p><p>Want to know more? Just write to me. We can all only learn from each other.</p><p>I hope you enjoyed it. As always, I look forward to your feedback!</p><p><em>Originally published in german language at </em><a href="https://mendixandme.de/index.php/2022/02/18/mendix-kann-man-nicht-ernst-nehmen-oder/"><em>https://mendixandme.de</em></a><em> on February 18, 2022.</em></p><p><em>From the Publisher -</em></p><p><em>If you enjoyed this article you can find more like it on our </em><a href="https://medium.com/mendix"><em>Medium page</em></a><em>. For great videos and live sessions, you can go to </em><a href="https://www.mendix.com/live/"><em>MxLive</em></a><em> or our community </em><a href="https://www.youtube.com/c/MendixCommunity/community"><em>Youtube pag</em></a><em>e.</em></p><p><em>For the makers looking to get started, you can sign up for a </em><a href="https://signup.mendix.com/link/signup/?source=direct"><em>free account</em></a><em>, and get instant access to learning with our </em><a href="https://academy.mendix.com/link/home"><em>Academy</em></a><em>.</em></p><p><em>Interested in getting more involved with our community? You can join us in our </em><a href="https://join.slack.com/t/mendixcommunity/shared_invite/zt-hwhwkcxu-~59ywyjqHlUHXmrw5heqpQ"><em>Slack community channel</em></a><em> or for those who want to be more involved, look into joining one of our </em><a href="https://developers.mendix.com/meetups/#meetupsNearYou"><em>Meetups</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f0a90fa2c5ff" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mendix/mendix-cant-be-taken-seriously-right-mendix-and-me-f0a90fa2c5ff">Mendix, ‘nice gimmick’ or the evolution of code? — Mendix and Me</a> was originally published in <a href="https://medium.com/mendix">Mendix Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Want to play a game? — Mendix and Me]]></title>
            <link>https://medium.com/mendix/want-to-play-a-game-mendix-and-me-4dda62c08931?source=rss-abaa26e23bd6------2</link>
            <guid isPermaLink="false">https://medium.com/p/4dda62c08931</guid>
            <category><![CDATA[yahtzee]]></category>
            <category><![CDATA[game-development]]></category>
            <category><![CDATA[mendix]]></category>
            <category><![CDATA[clevr]]></category>
            <category><![CDATA[low-code]]></category>
            <dc:creator><![CDATA[Andreas Blaesius]]></dc:creator>
            <pubDate>Thu, 20 Jan 2022 11:40:40 GMT</pubDate>
            <atom:updated>2022-08-24T12:29:47.052Z</atom:updated>
            <content:encoded><![CDATA[<h3>Want to play a game? — Mendix and Me</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ihnHxrzjTmh2ySASWbt5ug.png" /></figure><h3>This post is a little more fun than the others have been. It won’t be about big performance or best practices issues. It’s probably actually more about killing time during the lunch break.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IYYjrHaEioZe3FXYL25DVw.png" /></figure><p>One day at my desk, I searched for a way to pass some time. I have a dice cup on my desk. I think that dice are a great thing; they are a symbol of randomness and thus follow strict mathematical rules. This inspired me to implement one of the most popular dice games in a Mendix app. Of course, I am talking about Yahtzee (or “<em>Kniffel”</em> as we say in Germany). If you don’t know it, you can read about it <a href="https://en.wikipedia.org/wiki/Yahtzee">here</a> and how to play it.</p><p>Since this is a Mendix blog, I can’t do without skipping over the technical details. So here’s a little look under the hood. Of course, you can skip this part and go straight to the game if you would like to test your skills!</p><p><a href="https://my100108-sandbox.mxapps.io/">Mendix</a></p><h4>Domain Model</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*pw2kDqFKD1--JGZX.png" /></figure><p>Yes, of course, I could have made the whole thing simpler - but then it wouldn’t have been any fun, would it?</p><p><strong>Game</strong> is the central entity. It represents a single game. Each Game entity holds several things. First of all, Game is associated with <strong>DiceCup</strong>, which is also associated with <strong>Dice</strong> as necessary. Furthermore, you need <strong>LineItems, </strong>which<strong> </strong>represent the entries on the Yahtzee block. The items are created based on a configuration, which is stored in <strong>LineItemTemplates</strong>, in each game. As you can see the dice have an association with the LineItems. To better track the game, the dice are attached to the LineItem when the score is entered and the dice cup is reloaded with “fresh” dice. Finally, there is the <strong>HighScore entity</strong>. There are a maximum of 10 of this item. A classic arcade high score.</p><p>I know what you are thinking, “So many Calculated Attributes on one object? Isn’t that a bad idea?”.</p><p>Of course, it is! In this case, I decided to do it anyway for the sake of simplicity. Not least because there is always only exactly one DiceCup per game. So the number of attributes to be calculated remains small. Don’t you dare do that at home!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/269/1*bhllIlhtSjkJi_8G6242LA.jpeg" /><figcaption>Good guy developer meme</figcaption></figure><h4>Calculating Points</h4><p>After each roll, the system calculates for all open LineItems the points which would be noted if the player decides for this LineItem. For each type of LineItem, there is a separate calculation microflow.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/481/0*EubnS-JK7ElsyiaW.png" /></figure><p>The LineItem type is used in a central microflow to decide which of these calculation microflows will be executed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/986/0*Xv9G3vFRTlEGIRzX.png" /></figure><p>The calculations themselves are then straightforward and based on the frequency of the dice which can be found in the Calculate Attributes of the DiceCup. As an example, I would like to show the calculation of the FullHouse. The Full House Microflow looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*gLvhYIvJc2jdldKE.png" /></figure><p>The expression in the endpoint returns the points that would be reached in the FullHouse row with the dice rolled. It is based on the <strong>IsFullHouse</strong> Boolean.</p><pre>if   $IsFullHouse<br>then 25<br>else 0</pre><p>The IsFullHouse Boolean is determined with the following expression.</p><pre>(<br>  $DiceCup/Aces = 2<br>  or<br>  $DiceCup/Twos = 2<br>  or<br>  $DiceCup/Threes = 2<br>  or<br>  $DiceCup/Fours = 2<br>  or<br>  $DiceCup/Fives = 2<br>  or<br>  $DiceCup/Sixes = 2<br>)<br>and<br>(<br>  $DiceCup/Aces = 3<br>  or<br>  $DiceCup/Twos = 3<br>  or<br>  $DiceCup/Threes = 3<br>  or<br>  $DiceCup/Fours = 3<br>  or<br>  $DiceCup/Fives = 3<br>  or<br>  $DiceCup/Sixes = 3<br>)</pre><p>As soon as the player enters his points, the possible points to be reached are recorded as points, the LineItem is locked, the dice are associated with it, the DiceCup is filled with new dice and the counter of the DiceCup is set to 0.</p><h4>End of the game</h4><p>When all line items are filled, the game ends. The system checks if the player has made it to the HighScore. In this case, the game is saved and all players can admire his score.</p><p>In all cases, the player now has the option to try his luck one more time.</p><h4>Beat the High Score</h4><p>Now it’s up to you to get a place in the top 10! You don’t need a user account, You don’t even have to insert a coin. Just click this link and show us how good you are. Have fun!</p><p><a href="https://my100108-sandbox.mxapps.io/">Mendix</a></p><h4>Read more</h4><ul><li><a href="https://forum.mendix.com/link/questions/85957">Mendix Forum</a></li><li><a href="https://www.clevr.com/blog/gamification-fun-and-collaboration-in-developing-mendix-applications">Gamification, fun, and collaboration in developing Mendix applications</a></li></ul><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FrNSKhP7LLXo%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DrNSKhP7LLXo&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FrNSKhP7LLXo%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/490ab3165467d5377a3bcc307f994b5c/href">https://medium.com/media/490ab3165467d5377a3bcc307f994b5c/href</a></iframe><p><em>Originally published in german language at </em><a href="https://mendixandme.de/index.php/2022/01/20/willst-du-ein-spiel-spielen/"><em>https://mendixandme.de</em></a><em> on January 20, 2022.</em></p><p><em>From the Publisher -</em></p><p><em>If you enjoyed this article you can find more like it on our </em><a href="https://medium.com/mendix"><em>Medium page</em></a><em>. For great videos and live sessions, you can go to </em><a href="https://www.mendix.com/live/"><em>MxLive</em></a><em> or our community </em><a href="https://www.youtube.com/c/MendixCommunity/community"><em>Youtube pag</em></a><em>e.</em></p><p><em>For the makers looking to get started, you can sign up for a </em><a href="https://signup.mendix.com/link/signup/?source=direct"><em>free account</em></a><em>, and get instant access to learning with our </em><a href="https://academy.mendix.com/link/home"><em>Academy</em></a><em>.</em></p><p><em>Interested in getting more involved with our community? Join us in our </em><a href="https://join.slack.com/t/mendixcommunity/shared_invite/zt-hwhwkcxu-~59ywyjqHlUHXmrw5heqpQ"><em>Slack community channel</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4dda62c08931" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mendix/want-to-play-a-game-mendix-and-me-4dda62c08931">Want to play a game? — Mendix and Me</a> was originally published in <a href="https://medium.com/mendix">Mendix Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Transient attributes and access rights -be careful — Mendix and Me]]></title>
            <link>https://medium.com/mendix/transient-attributes-and-access-rights-be-careful-mendix-and-me-57cf0aa1c98e?source=rss-abaa26e23bd6------2</link>
            <guid isPermaLink="false">https://medium.com/p/57cf0aa1c98e</guid>
            <category><![CDATA[statelessserver]]></category>
            <category><![CDATA[tips]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[mendix]]></category>
            <category><![CDATA[low-code]]></category>
            <dc:creator><![CDATA[Andreas Blaesius]]></dc:creator>
            <pubDate>Wed, 01 Dec 2021 10:19:22 GMT</pubDate>
            <atom:updated>2022-01-21T11:49:05.140Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Transient attributes and access rights -be careful — Mendix and Me" src="https://cdn-images-1.medium.com/max/1024/1*2ZTkqc_s4VkCh4xgYQg_vw.png" /><figcaption>Transient attributes and access rights -be careful — Mendix and Me</figcaption></figure><h3>Transient attributes and access rights -be careful — Mendix and Me</h3><h3>I recently stumbled across something that at first seems strange, but when having a detailed look is perfectly logical. If it is not noticed, it can lead to very annoying errors whose reasons are very difficult to find. Admittedly, this is not a problem that occurs very often. But the better it is perhaps to have read about it before.</h3><h3>What happened?</h3><p>In principle, this was a standard process. Clicking on a button triggers a microflow. This microflow creates an object and initializes the attributes with values. This object, which has not yet been saved, is now transferred to a page on which the user can change or set certain attributes. Afterwards the user presses a button again which triggers a microflow in which the object is stored in the database.</p><p>So far, so standard. However, unexpected errors occurred. A closer look in the debugger showed that a particular attribute was initialized in the first microflow, but in the second microflow it had the default value from the domain model again. There was no place in the system where this attribute was changed or overwritten. Also the user had no possibility to see or change the attribute on the page. So where does the rollback come from?</p><h3>Security and the Stateless Server</h3><p>To understand what happened, you need to be familiar with the concept of Stateless Server (which was introduced with Mendix 7). In a nutshell, it means that the server does not save the state of objects at the end of a microflow cascade executed by the user. The current state of the objects used resides in the client (The user’s browser) and are transferred to the server with each new user interaction. The server then works with the state that was transferred by the client. This has advantages especially in the area of horizontal scalability which I don’t want to go into detail here.</p><p>By saving the current <strong>status in the clien</strong>t, the access rights play a major role. <strong>Only what the user is allowed to see can be stored in the client</strong>. If a user <strong>does not have read access to an attribute</strong>, the attribute is not transferred to the client. However, since the stateless server does not save the status, for security reasons it is also not transferred to the client, <strong>it is lost</strong>.</p><p>In the above example, this is exactly what happened. The user did not have read access to the attribute. However, the attribute had to be initialized for further processing. This did not work due to the client-server interaction.</p><h3>An example</h3><p>Let’s look at this very simple domain model</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/307/0*JlQZcwcbWPsWDx2A.png" /></figure><p>The Access Rights are defined as follows</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/954/0*UEwnjdeGaqLhgL6v.png" /></figure><p>As you can see, the user has no access to the HiddenAttribute.</p><p>Now we create an object in a microflow and initialize it with values. The HiddenAttribute is created with the string ‘Initialized’. Without committing, we now pass the created object to a page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*BZ6DaUQ0vkYsADEN.png" /></figure><p>As you can see, this microflow writes the values of the attributes into the log. If you now execute a microflow on the page which again writes the values to the log, you can see the differences. The result is that in the create microflow the initialized value is written into the log. In the microflow which is called from the page the attribute is uninitialized again. So the information is lost.</p><p>In comparison we now consider this microflow</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*m6DaIRr9_o0Qzk8d.png" /></figure><p>Here the object is committed during creation. Now the system behaves differently. The initialized value is also found in the microflow that is executed from the page. To consider this as a “solution” is a bit too short. You may not want to commit the object at this point. If you do, you may need a proper rollback strategy (if the user clicks Cancel). It also raises new questions. For example, what about an object that is committed and then changed? Let’s consider this microflow</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*y-LGhav2Par4sEpQ.png" /></figure><p>In this microflow, the object is created, initialized and committed. Then it is modified once with page refresh and once without page refresh. The result is the expected one. All changes that take place after the commit are lost.</p><h3>Conclusion</h3><p>Problems of this kind do not occur very often. Nevertheless, it is useful to be aware that this behaviour exists. There is no real “solution” to the problem. It all depends on what the specific use case is. In some cases it may make sense to simply give the user read permission. If this is not possible the object has to be committed or the value has to be initialized afterwards.</p><p>I hope to have helped one or the other. Have fun trying it out. As always, I look forward to feedback.</p><h4>Read more</h4><ul><li><a href="https://docs.mendix.com/refguide/mendix-client#2-13-runtime-server">Mendix Client - Studio Pro 9 Guide | Mendix Documentation</a></li><li><a href="https://docs.mendix.com/refguide/runtime-server">Runtime Server - Studio Pro 9 Guide | Mendix Documentation</a></li><li><a href="https://docs.mendix.com/refguide/committing-objects">Commit Object(s) - Studio Pro 9 Guide | Mendix Documentation</a></li></ul><p><em>Originally published in german language at </em><a href="https://mendixandme.de/index.php/2021/12/01/transiente-attribute-und-zugriffsrechte-be-careful/"><em>https://mendixandme.de</em></a><em> on December 1, 2021.</em></p><p><em>From the Publisher -</em></p><p><em>If you enjoyed this article you can find more like it at our </em><a href="https://medium.com/mendix"><em>Medium page</em></a><em>. For great videos and live sessions, you can go to </em><a href="https://www.mendix.com/live/"><em>MxLive</em></a><em> or our community </em><a href="https://www.youtube.com/c/MendixCommunity/community"><em>Youtube pag</em></a><em>e.</em></p><p><em>For the makers looking to get started, you can sign up for a </em><a href="https://signup.mendix.com/link/signup/?source=direct"><em>free account</em></a><em>, and get instant access to learning with our </em><a href="https://academy.mendix.com/link/home"><em>Academy</em></a><em>.</em></p><p><em>Interested in getting more involved with our community? You can join us in our </em><a href="https://join.slack.com/t/mendixcommunity/shared_invite/zt-hwhwkcxu-~59ywyjqHlUHXmrw5heqpQ"><em>Slack community channel</em></a><em> or for those who want to be more involved, look into joining one of our </em><a href="https://developers.mendix.com/meetups/#meetupsNearYou"><em>Meet ups</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=57cf0aa1c98e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mendix/transient-attributes-and-access-rights-be-careful-mendix-and-me-57cf0aa1c98e">Transient attributes and access rights -be careful — Mendix and Me</a> was originally published in <a href="https://medium.com/mendix">Mendix Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Multiple aggregations on one list? That can be optimized. — Mendix and Me]]></title>
            <link>https://medium.com/mendix/multiple-aggregations-on-one-list-that-can-be-optimized-mendix-and-me-ad4de30e08a9?source=rss-abaa26e23bd6------2</link>
            <guid isPermaLink="false">https://medium.com/p/ad4de30e08a9</guid>
            <category><![CDATA[mendix]]></category>
            <category><![CDATA[aggregation]]></category>
            <category><![CDATA[tips-and-tricks]]></category>
            <category><![CDATA[performance]]></category>
            <category><![CDATA[optimization]]></category>
            <dc:creator><![CDATA[Andreas Blaesius]]></dc:creator>
            <pubDate>Fri, 24 Sep 2021 09:20:46 GMT</pubDate>
            <atom:updated>2021-11-08T09:56:09.956Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JqxjzJEk4DPnTkcTdRU1rQ.png" /></figure><h3>Multiple aggregations on one list? That can be optimized. — Mendix and Me</h3><p>This article is about the optimization of database queries. More precisely, about the optimization of a special type of query, the aggregation.</p><h3>Aggregations in Mendix</h3><p>An aggregation is a calculation of the values of a certain column in a list of database entries. Typical aggregations are sums, averages, finding the largest or smallest element,…</p><p>We will look at aggregations where we are really only interested in the result, but where we don’t need the actual values or database entries. In particular, it is also about how to optimize the calls when you need multiple aggregations over the same list of objects.</p><p>In Mendix there is the “Aggregate List” action with which we can perform such aggregations on lists. Let’s consider the following data model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/341/0*2NhExTRQm06KgyfW.png" /></figure><p>The goal I want to achieve is to calculate a sum over all records for each of the attributes.</p><figure><img alt="https://www.mendix.com/pricing/" src="https://cdn-images-1.medium.com/max/970/1*HUEzJLQIRIGPAbc7QchY_w.png" /><figcaption><a href="https://www.mendix.com/pricing/">https://www.mendix.com/pricing/</a></figcaption></figure><h3>The obvious solution</h3><p>A very simple (and working) approach to this problem is the following.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*xMP5aksxN7cXLMvK.png" /></figure><p>In this microflow, a retrieve is executed first. On the resulting list, the aggregations are now made one after the other. The results are stored in a result object. This works flawlessly and the result is the desired one. However, the execution speed is very poor. On my sample database it took about 2500 milliseconds to execute this microflow.</p><p>The problem with this solution is that the list is first loaded from the database into the runtime. There it is aggregated. However, anyone who has worked directly with databases knows that databases themselves can perform aggregations. Databases are very good at that. So we want a way to let the database do the work.</p><h3>Best Practice</h3><p>The problem with the above solution is that Mendix only optimizes an aggregation if first, the retrieve and aggregation are directly together and second, no other action is performed on the list (even if it is “only” other aggregations). So, even if it looks like more effort at first sight, a better option is to make a dedicated retrieve for each aggregation. The corresponding microflow then looks like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*xHx4QZPQs5BGKOj1.png" /></figure><p>In this microflow, the same list is retrieved over and over again and an aggregation is performed right afterwards. Since none of these lists are used further, Mendix optimizes the calls and performs the aggregation directly on the database. The lists are not loaded into the runtime. Only the results of the aggregations can be found there.</p><p>On my sample database, this microflow is executed in about 240 milliseconds. So it is faster than the obvious solution by a factor of 10.</p><p>But why should you make 4 database calls to get one result each? In a database you could process the whole thing in one call? True. The final optimization of the whole thing makes use of exactly that.</p><h3>Even faster with OQL</h3><p>We have to admit that this solution can’t be done with Mendix board tools. We need the <a href="https://marketplace.mendix.com/link/component/66876">OQL Module</a> from the Mendix Marketplace. With the help of this module we can execute OQL queries on the database. This allows us to place all aggregations in a single database interaction. The corresponding microflow looks like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*S2Gkh6DIyogfyoM6.png" /></figure><p>Yes, it is actually only one action. The following statement is executed in it.</p><pre>SELECT<br>  SUM(Entity.FirstDecimal) AS SumDecimal,<br>  SUM(Entity.AnotherDecimal) AS SumAnotherDecimal,<br>  SUM(Entity.ThirdDecimal) AS SumThirdDecimal,<br>  SUM(Entity.LastDecimal) AS SumLastDecimal<br>FROM<br>  MyFirstModule.Entity AS Entity</pre><p>The Execute OQL statement action executes the code on the database and directly creates a result object for us. The only thing to note here is that the selected aliases must match the attribute names of the result entity.</p><p>On my sample database, this microflow is executed in about 90 milliseconds. So it is again a considerable performance jump between the best practice and the OQL variant.</p><h3>Conclusion</h3><p>For aggregations, you should at least always use Mendix best practice and retrieve a list exclusively for one aggregation. Only then will the platform optimize the execution and let the database do the work. In some cases, especially with many records or complex data structures, it can be useful to further optimize by using OQL. This graphic shows the difference in execution speed impressively.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*MjS0uOSjK_a7aK2g.png" /></figure><p>Here it becomes clear how bad the performance can be with the obvious solution. The difference between the best practice and the OQL solution becomes even clearer when only these two are compared.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/745/0*jezZcVFun6LvnNQ9.png" /></figure><p>You should also keep in mind that the example shown is a very simple query. The database does not need to execute any complicated joins. If these are necessary (and in real examples they are almost always) the difference can be much more significant.</p><p>As always, I wish you a lot of fun trying this out. I am also always very happy about your feedback - let me know what you think!</p><h4>Read more</h4><ul><li><a href="https://docs.mendix.com/refguide/aggregate-list">Aggregate List - Studio Pro 9 Guide | Mendix Documentation</a></li><li><a href="https://docs.mendix.com/refguide/oql">OQL - Studio Pro 9 Guide | Mendix Documentation</a></li><li><a href="https://docs.mendix.com/howto/logic-business-rules/optimizing-microflow-aggregates">Optimize Microflow Aggregates - Studio Pro 9 How-to&#39;s | Mendix Documentation</a></li></ul><p><em>Originally published in german language at </em><a href="https://mendixandme.de/index.php/2021/09/24/mehrere-aggregationen-auf-einer-liste-das-laesst-sich-optimieren/"><em>https://mendixandme.de</em></a><em> on September 24, 2021.</em></p><p><em>From the Publisher -</em></p><p><em>If you enjoyed this article you can find more like it at our </em><a href="https://medium.com/mendix"><em>Medium page</em></a><em>. For great videos and live sessions, you can go to </em><a href="https://www.mendix.com/live/"><em>MxLive</em></a><em> or our community </em><a href="https://www.youtube.com/c/MendixCommunity/community"><em>Youtube pag</em></a><em>e.</em></p><p><em>For the makers looking to get started, you can sign up for a </em><a href="https://signup.mendix.com/link/signup/?source=direct"><em>free account</em></a><em>, and get instant access to learning with our </em><a href="https://academy.mendix.com/link/home"><em>Academy</em></a><em>.</em></p><p><em>Interested in getting more involved with our community? You can join us in our </em><a href="https://join.slack.com/t/mendixcommunity/shared_invite/zt-hwhwkcxu-~59ywyjqHlUHXmrw5heqpQ"><em>Slack community channel</em></a><em> or for those who want to be more involved, look into joining one of our </em><a href="https://developers.mendix.com/meetups/#meetupsNearYou"><em>Meet ups</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ad4de30e08a9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mendix/multiple-aggregations-on-one-list-that-can-be-optimized-mendix-and-me-ad4de30e08a9">Multiple aggregations on one list? That can be optimized. — Mendix and Me</a> was originally published in <a href="https://medium.com/mendix">Mendix Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[New instance or just a reference? When does a retrieve return what? — Mendix and Me]]></title>
            <link>https://medium.com/mendix/new-instance-or-just-a-reference-when-does-a-retrieve-return-what-mendix-and-me-fa9881877c4b?source=rss-abaa26e23bd6------2</link>
            <guid isPermaLink="false">https://medium.com/p/fa9881877c4b</guid>
            <category><![CDATA[reference]]></category>
            <category><![CDATA[instance]]></category>
            <category><![CDATA[tips]]></category>
            <category><![CDATA[mendix]]></category>
            <category><![CDATA[low-code]]></category>
            <dc:creator><![CDATA[Andreas Blaesius]]></dc:creator>
            <pubDate>Fri, 07 May 2021 10:47:35 GMT</pubDate>
            <atom:updated>2021-07-09T10:47:05.199Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xJedmTT33Sk2yM3Hk6teQw.png" /></figure><h3>New instance or just a reference? When does a retrieve return what? — Mendix and Me</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ngX3aX5asPD2u21T.png" /></figure><p>I came across this topic when it led to a real problem in a real project. To put a long story short, a change in the code changed the status of an object from auto-committed to normal. This then resulted in a completely different place in our app, to no longer react as it did before. Changes to an object were suddenly no longer reflected in the database.</p><h3>What happened?</h3><p>Let us first look at the following data model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/760/0*DjLSvBEzfxyckJ5D.png" /></figure><p>The attributes of the two entities do not matter here. They could also be any other attributes and types.</p><p>The B entity to be committed was in a list. At the end of the process, this list was committed. Before that, a list of entity A was iterated over. Within this iteration, the objects of type B were retrieved individually via a retrieve by association and values in them were changed in a change action. In a previous version, these changes were also reflected in the list. The retrieve by association created another reference to the same instance of the object that was already in the list. When committing the list, the changes were committed and reflected in the database.</p><p>However, after a code change elsewhere, it behaved completely differently. The retrieve by association now created a new instance of the same object. The changes made in the iteration were therefore no longer reflected in the list and were not written to the database.</p><h3>But why?</h3><p>So what had changed? After restoring the previous version and a direct comparison, it turned out that the objects of B had the status ‘autocommitted’ at the time of the iteration. In the new version, however, they had the status ‘normal’.</p><p>The assumption was that the status decides whether a cached version of an object is referenced or whether a new instance of the object is created.</p><figure><img alt="https://bit.ly/MXW21" src="https://cdn-images-1.medium.com/max/1024/1*KEVX4H5BL_VBX3sHpw_smw.png" /><figcaption><a href="https://bit.ly/MXW21">https://bit.ly/MXW21</a></figcaption></figure><h3>How does which status behave?</h3><p>To find out I created a simple demo application that runs through the scenario with all possible variants. The result is that retrieves by association to objects in ‘Instantiated’ or ‘Autocommitted’ status create a new reference to the cached object while the same retrieve to an object in ‘Normal’ status creates a new instance even if the object is still in the cache.</p><h3>Conclusion</h3><p>If you take advantage of the fact that you can create a new instance or just a reference when you retrieve by association when developing a microflow, it is important to keep in mind which states the objects can have at the time of execution and whether they can be changed by code updates. If they change, this can have unexpected consequences. Especially in complex processes, these errors are not easy to find, since cause and effect can lie in completely different places in your code.</p><p>Have fun trying it out. As always, I look forward to your feedback.</p><h4>Read more</h4><ul><li><a href="https://bit.ly/MXW21">Mendix World 2021 | September 7-9, 2021 | Low-Code App Dev Event</a></li><li><a href="https://www.mendix.com/mendix-world/tracks/">Tracks | Mendix World 2021</a></li></ul><p><em>Originally published in german language at </em><a href="https://mendixandme.de/index.php/2021/05/07/neue-instanz-oder-nur-eine-referenz-wann-liefert-ein-retrieve-was/"><em>https://mendixandme.de</em></a><em> on May 7, 2021.</em></p><p><em>From the Publisher -</em></p><p><em>If you enjoyed this article you can find more like it at our </em><a href="https://medium.com/mendix"><em>Medium page</em></a><em> or at our own </em><a href="https://developers.mendix.com/community-blog/"><em>Community blog site</em></a><em>.</em></p><p><em>For the makers looking to get started, you can sign up for a </em><a href="https://signup.mendix.com/link/signup/?source=direct"><em>free account</em></a><em>, and get instant access to learning with our </em><a href="https://academy.mendix.com/link/home"><em>Academy</em></a><em>.</em></p><p><em>Interested in getting more involved with our community? You can join us in our </em><a href="https://join.slack.com/t/mendixcommunity/shared_invite/zt-hwhwkcxu-~59ywyjqHlUHXmrw5heqpQ"><em>Slack community channel</em></a><em> or for those who want to be more involved, look into joining one of our </em><a href="https://developers.mendix.com/meetups/#meetupsNearYou"><em>Meet ups</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fa9881877c4b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mendix/new-instance-or-just-a-reference-when-does-a-retrieve-return-what-mendix-and-me-fa9881877c4b">New instance or just a reference? When does a retrieve return what? — Mendix and Me</a> was originally published in <a href="https://medium.com/mendix">Mendix Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Unique Foreign Keys and Concurrency: Mendix and Me]]></title>
            <link>https://medium.com/mendix/unique-foreign-keys-and-concurrency-mendix-and-me-3f30c10b7898?source=rss-abaa26e23bd6------2</link>
            <guid isPermaLink="false">https://medium.com/p/3f30c10b7898</guid>
            <category><![CDATA[concurrency]]></category>
            <category><![CDATA[mendix]]></category>
            <category><![CDATA[foreign-key]]></category>
            <category><![CDATA[tips]]></category>
            <category><![CDATA[uniqueness]]></category>
            <dc:creator><![CDATA[Andreas Blaesius]]></dc:creator>
            <pubDate>Wed, 31 Mar 2021 11:06:38 GMT</pubDate>
            <atom:updated>2021-07-09T10:54:13.206Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bY4qcX5WakV9hst4hyAcYA.png" /></figure><h3>Even though Mendix manages relations via the domain model and you usually won’t come into contact with keys and foreign keys, it is very likely that you will reach a point where you need them. Typical examples are the avoidance of cross-module associations or data that you receive from a third-party system and want to cache locally.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VAvrisdOx5qs_oQAx3f2vA.png" /></figure><p>In many cases, it is necessary for a key to exist only once. For example, if you synchronize records from a foreign system, you want to avoid storing the same record multiple times. A simple but effective approach is to use the CreateOrRetrieveIfExisting pattern.</p><p>Let’s look at the following data set:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/397/0*pVMa1Zx5kZcjRCDp" /></figure><p>The identifier attribute is the unique key. If a record with a certain key is needed, a CreateOrRetrieveIfExisting microflow can be used with an existing record or, if there is no such record, to create a new record. This is used in event-driven systems where an event in another system creates or changes a record that must be kept synchronous. The corresponding microflow would now look as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*VSUOh1KuYcfeC6CV" /></figure><p>For a given identifier, the system now searches for a data record from the database and creates it if necessary. This way, you can ensure that you always get a record and that a record exists only once.</p><figure><img alt="https://bit.ly/MXW21" src="https://cdn-images-1.medium.com/max/1024/1*KEVX4H5BL_VBX3sHpw_smw.png" /><figcaption><a href="https://bit.ly/MXW21">https://bit.ly/MXW21</a></figcaption></figure><h3>The Problem: Concurrency</h3><p>This pattern works perfectly, but has one problem: It cannot handle concurrency. Especially (but not only) with event-driven architecture, there can be several events within a short time that all refer to the same record. If the record already exists, this is not a problem. If, however, it does not exist at this point in time, several processes are running that know nothing about each other. None of these processes can find the object in the database because the transaction of the other processes is not finished at this time. This is especially dangerous if the process has a long runtime. The result is that each of these processes creates the record over again, with the result that the record exists several times in the database.</p><h3>The Solution: Database-Level Validation and Retry Mechanism</h3><p>First, we need to create a unique constraint in the database. Fortunately, this can be done easily using the Mendix Domain Model. To do this, we create a validation rule for the identifier that looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*V3cEaumHxM7qjzAK" /></figure><p>The database now does not allow the same value to exist more than once. If you try to commit an object which has an already used identifier, an exception is thrown.</p><p>Of course, we do not want our process to terminate with an exception. Ideally we want to know the problem already when we generate it. For this, the CreateOrRetrieveIfExisting microflow can be adapted as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*lFMdzICYHQf-oFbv" /></figure><p>The object is now saved directly when it is created. This leads to the fact that a database lock exists and other processes must wait if necessary for the end of the first process. If it turns out that the first process has already created the object, the create action throws an exception.</p><p>Now we know there is a problem as soon as we create the problem. However, it would be more convenient if our process would continue successfully and not terminate because of an exception. If we extend the microflow with error handling in combination with a retry mechanism, we can achieve exactly this comfort.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*psyyqL6ZHjGn2jJt" /></figure><p>The IsRetry variable is a boolean which is initialized with ‘false’ and changed to ‘true’ in case of an error. This ensures that the retry is attempted only once. More is not necessary for this problem.</p><p>If the first process now ends its transaction, an exception is thrown in the Create Action in the other processes. This is handled by starting the microflow again from the beginning. Due to the completed transaction of the first process, the data set is now found in the database and can be used. Parallelism still exists if different data sets are created in parallel. If it concerns the same data record, then with the first creation process (if necessary) one waits for the fact that the first process is locked. These queries are thus processed serially, while in the further course parallelism is again given.</p><p>I hope this article is helpful. As always, I am happy to hear any feedback.</p><p><em>Originally published in German at</em><a href="https://mendixandme.de/index.php/2021/03/31/eindeutige-fremdschluessel-und-parallelitaet/"><em> https://mendixandme.de</em></a><em> on March 31, 2021.</em></p><p><em>From the Publisher -</em></p><p><em>If you enjoyed this article you can find more like it at our </em><a href="https://medium.com/mendix"><em>Medium page</em></a><em> or at our own </em><a href="https://developers.mendix.com/community-blog/"><em>Community blog site</em></a><em>.</em></p><p><em>For the makers looking to get started, you can sign up for a </em><a href="https://signup.mendix.com/link/signup/?source=direct"><em>free account</em></a><em>, and get instant access to learning with our </em><a href="https://academy.mendix.com/link/home"><em>Academy</em></a><em>.</em></p><p><em>Interested in getting more involved with our community? You can join us in our </em><a href="https://join.slack.com/t/mendixcommunity/shared_invite/zt-hwhwkcxu-~59ywyjqHlUHXmrw5heqpQ"><em>Slack community channel</em></a><em> or for those who want to be more involved, look into joining one of our </em><a href="https://developers.mendix.com/meetups/#meetupsNearYou"><em>Meet ups</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3f30c10b7898" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mendix/unique-foreign-keys-and-concurrency-mendix-and-me-3f30c10b7898">Unique Foreign Keys and Concurrency: Mendix and Me</a> was originally published in <a href="https://medium.com/mendix">Mendix Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>