Is there a way where I can transfer data from one entity to the attributes of another?
0
Hi, I have two entities, Parts and PartsPrintRequest. The Parts entity has the following attributes: "PartName, PartNumber and PartStatus." The PartsPrintRequest has the following attributes: "PartName, PartNumber, PartStatus, PrintQuantity, PrintNumber". The print attributes are used for the print request part of this entity. Let's say that the Parts data already comes preloaded. The user adds in the print request data manually. I want to display two tables, one of just the Parts entity and one of the PartsPrintRequest. Is there a way where I can transfer the data from the Parts entity to the attributes of the PartsPrintRequest entity? Below is a microflow that I am building, here's how it functions: It retrieves the lists from both entities, Makes sure that the PartsPrintRequest list is not empty (to avoid infinite addition of data). If it is, the microflow will add the latest entry from the Parts list to the PartsPrintRequest and returns the list. If it is not empty, using a nested loop (I'm still pretty new to Mendix and coming from traditional coding, sorry if it's a bit messy) it goes through each entry of the two lists and compares it. If the PartsName is the same on both entries then continue the event, if not, then add this entry to the PartsPrintRequest table and return it. This microflow only works if there is one entry in the Parts list but if there are 2 or more entries, the nested loop reads the list in a random order (let's say, from bottom to top and then from top to bottom) which results to adding duplicates in the PartsPrintRequest list. Is there another way to do this?
asked
Tyron Corpuz
1 answers
1
You can follow these steps:
Before looping through Parts, retrieve the list of PartsPrintRequest records that already exist. This will help you avoid adding duplicates. You can filter the list based on the PartName (or PartNumber, or other attributes, depending on your requirements).
Instead of just looping through and comparing each entry randomly, check if a record already exists in the PartsPrintRequest list before adding a new one. For this, you can use the Find or Contains functionality to verify that the PartName from Parts is not already in PartsPrintRequest.
Nested loops can be inefficient and prone to errors, especially when working with larger data sets. Instead, consider iterating over the Parts list and checking the existence of each PartName in the PartsPrintRequest list (or using a List of Strings or Set to track already added parts).
You can optimize the lookup for existing parts using a Microflow or XPath to retrieve PartsPrintRequest records by PartName.