One to many is an import setting for cases where a single parent record needs to create several child records — order receipts imported as line items, say, where one receipt contains several items. You turn on One to many on the import and give it a Path to many, the JSON path to the child records; integrator.io then writes one destination record per child. Path to many reaches only the first-level array, so child records inside a nested array need a workaround: two flows that work together, a pre-save page hook, or a post-response mapping hook. This article explains how child records are processed, how to set up one to many, and the workarounds for nested arrays.
How child records are processed
One-to-many processing is local to the import step: integrator.io writes the child records, then rejoins them into the original parent record for the steps that follow. What happens to the parent depends on how the children fared and on the step's error handling:
| Child outcomes | What happens to the parent |
|---|---|
| All children succeed or are ignored | The parent continues to the next step. |
| One or more children fail, with default error handling | The parent stops at this step. Successful children aren't rolled back; the failed children have to be corrected and retried before the parent continues. |
| One or more children fail, with Proceed to the next application regardless turned on | The parent continues despite the failures, which remain open, retryable errors. Retrying an error reprocesses this step only; the steps after it aren't run again for that record. |
Proceed to the next application regardless is the import step's error-handling setting in Flow builder — set it from the step's Actions menu; see Configure flow step options. It's off by default.
When the parent continues after a failure, the flow collects the responses — successes and failures — from each child operation, and response mapping processes all of them. A post-response mapping hook runs once, after every child record has been processed, with the full context of the parent and its children, including which children succeeded and which failed.
Set up one to many
Use one to many when a parent record moves through the flow but you need to write the child records it contains. For example, you export 3PL Central purchase order receipts and import them into NetSuite as item receipts: each receipt has more than one item, so each receipt has a one-to-many relationship with the item receipts.
As a second example, you export 3PL Central order data and import each item as a NetSuite custom record:
{
"orderData": {
"orderId": "1234512345",
"customerEmail": "john.doe@email.com",
"items": [
{ "sku": "Business Cards", "itemId": "67890" },
{ "sku": "Pens", "itemId": "12345" }
]
}
}Here orderData has a one-to-many relationship with items. To have one orderData record create a record per item:
- Go to Build
> Flows, open the flow, and then select the import step to open its editor.
- In General, under the connection, set One to many to Yes (advanced).
- Enter the Path to many; see Path to many.
- Select Save & close.
Path to many
Path to many is the JSON path to the child records the parent creates. If the records are JSON objects, select or enter the path to the child array; for array or row-based data, leave it empty. In the example above, the path is orderData.items.
If you enter the path by hand, confirm it with Preview and check the records it returns, because integrator.io doesn't report an error when a path is misspelled or doesn't exist. See Preview import data.
Once one to many is set, each child record carries a _PARENT object with the parent record's fields, so a mapping can reference parent values — orderId and customerEmail here — while processing an individual child:
{
"record": {
"_PARENT": {
"orderData": {
"orderId": "1234512345",
"customerEmail": "john.doe@email.com"
}
},
"sku": "Pens",
"itemId": "12345",
"serialNumbers": [
{ "code": "abvyPHCS" },
{ "code": "SWFAqWGt" }
]
},
"settings": {
"integration": {},
"flow": {},
"flowGrouping": {},
"connection": {},
"iClient": {},
"import": {}
}
}Path to many reaches only the first-level array. If the child records are in a nested array, see Access nested arrays.
Access nested arrays
A nested array is a child record that contains its own array — each item in a purchase order carrying a list of serial numbers, for example:
{
"orderData": {
"orderId": "1234512345",
"customerEmail": "john.doe@email.com",
"items": [
{
"sku": "Business Cards",
"itemId": "67890",
"serialNumbers": [ { "code": "swRkEQmd" }, { "code": "EQ8vELmm" } ]
},
{
"sku": "Pens",
"itemId": "12345",
"serialNumbers": [ { "code": "abvyPHCS" }, { "code": "SWFAqWGt" } ]
}
]
}
}Path to many can reach orderData.items but not serialNumbers. Two workarounds reach the nested records: use two flows, or use a hook script.
Use two flows to access nested arrays
Two flows work together to flatten the data so the nested array becomes a first-level array:
- The first flow exports the receipts from the source application (3PL Central, in this example), uses one to many to break them into items, flattens each item with a mapping or a transformation so the serial numbers become the first-level array, and posts the result to a webhook listener. See Create webhook listeners.
- The second flow starts from that listener. Its records have the serial numbers as a first-level array, which its import maps with One to many.
Use scripts to access nested arrays
A hook at one of two points in the flow can restructure the records instead:
- A pre-save page hook on the export formats, filters, and restructures the records before they move through the rest of the flow, so every later step sees the flattened structure.
- A post-response mapping hook on a lookup step that retrieves the one-to-many arrays runs after response mapping and regular mapping, and can turn the nested records into individual records before they pass to the next step. Choose this when you need the results as individual records.
For where each hook is set and which script formats it accepts, see Export and import hooks.