First add an IsNew (Boolean) attribute to the Ingredient_Staging entity and set it to true during the Excel import. Also configure access so that only the owner can read and write these staging records. This ensures that if multiple users perform imports at the same time, their data remains isolated and does not interfere with each other.
In the transformation microflow, retrieve only the staging records where Owner = CurrentUser and IsNew = true. Before entering the loop, create two in-memory cache lists: IngredientList and SupplierList. These lists help prevent creating duplicate Ingredient or Supplier objects during the same import process.
Inside the loop, for each staging record, check whether the corresponding Ingredient and Supplier already exist in the cache lists using their business keys (for example, material number for Ingredient and supplier number for Supplier). If they do not exist, create them and add them to the lists. If they already exist, reuse them instead of creating duplicates. Then create or update the IngredientSupplier junction entity based on your defined unique key, typically a combination such as Ingredient + Supplier + Year or Ingredient + Supplier + SnapshotDate, depending on your pricing history logic.
After processing each staging record, set its IsNew attribute to false so it will not be processed again in future runs. Once the loop is complete, perform a batch commit (if more data exists) on the IngredientList and SupplierList. This improves performance and ensures a consistent, duplicate-free transformation from staging to your normalized master and transactional tables.
hi,
Move data from:
Ingredient_Staging →
Ingredient + Supplier + IngredientSupplier
MF_Transform_StagingRetrieve all Ingredient_Staging records (or only unprocessed ones).
Loop through the list.
Retrieve Ingredient using a business key, for example:
[component_material_num = $Staging/component_material_num]
If empty → Create + set attributes + Commit
Else → Use existing record
Retrieve Supplier:
[supplier_number = $Staging/supplier_number]
If empty → Create + Commit
Else → Use existing
Retrieve:
[IngredientSupplier_Ingredient = $Ingredient and IngredientSupplier_Supplier = $Supplier and year = $Staging/year]
If empty →
Create IngredientSupplier
Set pricing fields
Set associations
Commit
Else →
Update pricing
Commit
Add Unique Indexes:
This is mandatory for data integrity.
Delete or mark Ingredient_Staging as processed.
• No duplicate master data
• Supports historical pricing
• Safe for re-import
• Follows Mendix best practice for normalization