When working with preMap scripts in integrator.io, it’s easy to assume that the script applies to the entire dataset you pass in. But things behave a little differently when you enable the One-to-Many option on an import step.
This happened while I was working on a project to move data between DealCloud (Intapp) and Reprisk using CSV files from FTP, and I thought it would be useful to share what I learned.
What I expected:
I had a file via FTP with more than 100 records.
I wrote a preMap script, assuming it would let me run logic across the entire file before the mappings and before the data reached the import step.
What actually happened:
Once I enabled One-to-Many on the import step, I realized something important:
- The preMap script only applies to each grouped record, meaning the logic I wrote was running per record (or per group), not on the original full array of records from the file.
- This meant that any logic depending on the entire data/dataset simply didn’t work the way I expected.
So instead of running once across all 100+ records, my script was only acting inside each smaller grouped set of records.
The solution I found:
Instead of using preMap, I switched to a postResponseMap before the import step - this turned out to be more accurate, especially for a lookup step.
- postResponseMap gives you access to the data after your export but before the import.
- This meant I could apply my logic to the entire dataset, not just individual grouped records.
- Once transformed, the data flowed into the import step exactly as needed.
The result: my logic worked across the full dataset, just the way I originally intended.
Quick Tip for Debugging:
If you ever don’t know what data your script is getting, you can use console.log() to print the data. This shows you exactly what’s coming in and makes it much easier to fix problems.
Key takeaways :
-
preMap is great when your logic only needs to act on each individual record.
-
With One-to-Many enabled, remember that preMap sees only the grouped records, not the full dataset.
-
Use postResponseMap when you need to apply transformations to the entire dataset before import.
-
Always test small batches first - it’s easier to see whether your logic runs per record or per group.
This small adjustment saved me a lot of debugging time. Hopefully it helps others avoid the same confusion !!!!