The built-in repair utility is good but won’t fix the root cause if your batch IDs are inconsistent. Here’s what worked for us in a similar situation.
First, run this validation query to confirm the ID mismatch pattern:
SELECT DISTINCT b.BatchNumber, mct.SourceBatchID
FROM Batch b
LEFT JOIN MaterialConsumptionTransaction mct
ON b.BatchID = mct.ConsumingBatchID
WHERE mct.SourceBatchID IS NULL
If you see records where BatchNumber exists but SourceBatchID is null, that confirms the linking problem.
For the repair approach, you need to address all three focus areas systematically:
1. Import Mapping Validation:
Create a mapping table that translates old format to new format. This becomes your reference for all corrections. Export your current batch master and material transactions to CSV, then build a lookup table showing old ID → new ID for every affected batch.
2. Batch ID Consistency:
You have two options:
- Option A: Update the batch master records to use the legacy ID format (simpler if legacy format meets your current standards)
- Option B: Update all material consumption transaction references to use the new format (better if new format is your standard going forward)
We chose Option B. Created a stored procedure that updated MaterialConsumptionTransaction.SourceBatchID using our mapping table:
UPDATE MaterialConsumptionTransaction
SET SourceBatchID = mapping.NewBatchID
FROM BatchIDMapping mapping
WHERE MaterialConsumptionTransaction.SourceBatchID = mapping.OldBatchID
3. Genealogy Data Repair:
After fixing the ID consistency, run the Genealogy Rebuild utility:
- Go to System Administration → Data Management → Genealogy Rebuild
- Select date range covering your imported batches
- Choose “Rebuild parent-child relationships” option
- Run in validation mode first to preview changes
- Execute the rebuild (this can take 2-4 hours for 6 months of data)
The rebuild utility will reprocess all material consumption transactions in chronological order and reconstruct the genealogy tree based on the corrected batch ID references.
Critical steps:
- Back up your database before any updates
- Test the entire process in a development environment first
- Document your batch ID mapping table - you’ll need it for future reference
- After rebuild, spot-check 20-30 batches across different time periods to verify the genealogy links are correct
- Run the standard genealogy validation report to confirm no orphaned nodes remain
One gotcha we encountered: if any of your imported batches have status=“Archived”, the genealogy rebuild skips them. You need to temporarily change status to “Complete”, run the rebuild, then change back to “Archived”.
This approach fixed our 3,800+ orphaned batch records. The key is fixing the data consistency issue first, then letting the built-in tools do the genealogy reconstruction. Don’t try to manually recreate the parent-child links - the genealogy engine needs to build them from the transaction history to maintain proper audit trails.