Sub topic 7
Preparing Source Data with Templates
This chapter assumes you know the difference between master data and transactional data. You should also be able to edit CSV or XML files and spreadsheets, and you should have created a migration project that contains at least one migration object.
What a template is
When you use the file approach, the migration cockpit provides a template for each migration object. A template is an XML or CSV file that defines the structures and fields the object expects. You download it from the cockpit, fill it with legacy data, and upload it again.
A template has several sheets (XML) or several files (CSV). Each sheet matches one structure of the object. For example, a customer object might have a sheet for general data, one for addresses, and one for bank details. Sheets are linked by a key field, so a row in the address sheet belongs to the row in the general sheet that has the same key.
The preparation workflow
- Download the template from the migration object in your project. Always use the template from your own project, because its structure matches your release.
- Extract the legacy data and arrange it in the template's structures.
- Map each legacy field to a template field. Fields marked as mandatory must be filled.
- Pre-check the data outside the cockpit.
- Upload the files and continue with validation.
Common errors in source data
Most load errors come from a small set of causes:
- Duplicate keys, where two rows claim the same customer or material number.
- Values longer than the target field allows, such as a 50-character name in a 40-character field.
- Missing mandatory fields.
- Child rows with no matching parent row, such as an address for a key that is not in the general sheet.
- Wrong formats for dates, numbers, or leading zeros. Spreadsheet programs often drop leading zeros from account numbers, so check these fields.
Do not rename sheets, delete columns, or change the header rows of a template. The upload expects the original layout.
Pre-checking with a script
Fixing these problems before upload saves a validation cycle. The script below reads a CSV extract, reports values that are too long, and reports duplicate keys. The file and field names are placeholders. Replace them with the names from your own file and the field lengths shown in the template.
import csv
from collections import Counter
def precheck(path, key_field, max_lengths):
"""Return a list of problems found in a source CSV before upload."""
problems = []
keys = Counter()
with open(path, newline="", encoding="utf-8") as f:
for line_no, row in enumerate(csv.DictReader(f), start=2):
keys[row[key_field]] += 1
for field, limit in max_lengths.items():
if len(row[field]) > limit:
problems.append(f"line {line_no}: {field} is longer than {limit} characters")
problems += [f"duplicate key {k}" for k, n in keys.items() if n > 1]
return problems
for problem in precheck("customers.csv", "CustomerId", {"Name": 40}):
print(problem)Line numbers start at 2 because line 1 holds the header. The script does not replace the cockpit's validation. It only removes the most common errors early.
Summary table
| Problem | Typical sign | Fix before upload |
|---|---|---|
| Duplicate key | Same ID on several rows | Remove or merge rows |
| Value too long | Field exceeds template length | Shorten or correct the value |
| Missing parent | Child row has no matching key | Add the parent row or drop the child |
| Lost leading zeros | `123` instead of `000123` | Format the column as text |
Exercise
A customer extract passes your pre-check, but the upload reports that several address rows are rejected. Which common cause does the pre-check in this chapter not cover, and how would you find the affected rows?
Show answer
The pre-check does not test for child rows without a parent. Compare the key values in the address sheet with those in the general data sheet, and list address keys that do not appear in the general sheet. Then add the missing parent rows or remove the orphaned address rows.