# Flatten a record with an array of objects into multiple records

**URL:** <https://connective.celigo.com/t/flatten-a-record-with-an-array-of-objects-into-multiple-records/6006>\
**Category:** Integrator.io\
**Created:** [January 20, 2026, 6:25pm UTC](https://connective.celigo.com/t/flatten-a-record-with-an-array-of-objects-into-multiple-records/6006 "2026-01-20T18:25:19Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jim\_Clarke](https://avatars.discourse-cdn.com/v4/letter/j/48db29/32.png) [@Jim\_Clarke](https://connective.celigo.com/u/Jim_Clarke)\
**Post date:** [January 20, 2026, 6:25pm UTC](https://connective.celigo.com/t/flatten-a-record-with-an-array-of-objects-into-multiple-records/6006/1 "2026-01-20T18:25:19Z")

</div>

I have a MSCRM export that returns records that contain an array of objects. I would like to flatten the results into multiple records. Transformation has an option to create output rows from an input record, but no option to create output records from input rows. Is this a formatting change that requires JavaScript?

I need to reformat the sample below to output 2 records without any arrays.

 ![image](https://us1.discourse-cdn.com/flex001/uploads/celigo/original/2X/2/28824cd3ea3bf6804f04489307a9cf500c0fed33.png)

---

<div class="post-metadata">

**Author:** ![tylerlamparter](https://sea1.discourse-cdn.com/flex001/user_avatar/connective.celigo.com/tylerlamparter/32/9204_2.png) [@tylerlamparter](https://connective.celigo.com/u/tylerlamparter)\
**Post date:** [January 20, 2026, 6:31pm UTC](https://connective.celigo.com/t/flatten-a-record-with-an-array-of-objects-into-multiple-records/6006/2 "2026-01-20T18:31:05Z")

</div>

Yeah, this requires a pre-save page script to take the 1-record input and return 2 records on output. You could also use one-to-many on all your flow steps, but you may have reasons that won't work for you.

---

<div class="post-metadata">

**Author:** ![Jim\_Clarke](https://avatars.discourse-cdn.com/v4/letter/j/48db29/32.png) [@Jim\_Clarke](https://connective.celigo.com/u/Jim_Clarke)\
**Post date:** [January 20, 2026, 6:49pm UTC](https://connective.celigo.com/t/flatten-a-record-with-an-array-of-objects-into-multiple-records/6006/3 "2026-01-20T18:49:47Z")

</div>

That’s what I suspected. Do you have a quick JavaScript example for that?

---

<div class="post-metadata">

**Author:** ![tylerlamparter](https://sea1.discourse-cdn.com/flex001/user_avatar/connective.celigo.com/tylerlamparter/32/9204_2.png) [@tylerlamparter](https://connective.celigo.com/u/tylerlamparter)\
**Post date:** [January 20, 2026, 7:12pm UTC](https://connective.celigo.com/t/flatten-a-record-with-an-array-of-objects-into-multiple-records/6006/4 "2026-01-20T19:12:17Z")

</div>

Something like this

```javascript
function preSavePage(options) {
  const out = [];

  (options.data || []).forEach(parent => {
    const children = parent && parent.contact_customer_accounts;

    // If no children array, output nothing for this parent (change if you want a passthrough)
    if (!Array.isArray(children) || children.length === 0) return;

    // Parent copy without the array
    const parentCopy = Object.assign({}, parent);
    delete parentCopy.contact_customer_accounts;

    // One output record per child
    children.forEach(child => {
      out.push(Object.assign({}, child, { _PARENT: parentCopy }));
    });
  });

  return {
    data: out,
    errors: options.errors,
    abort: false,
    newErrorsAndRetryData: []
  };
}

```

---

<div class="post-metadata">

**Author:** ![Jim\_Clarke](https://avatars.discourse-cdn.com/v4/letter/j/48db29/32.png) [@Jim\_Clarke](https://connective.celigo.com/u/Jim_Clarke)\
**Post date:** [January 20, 2026, 8:40pm UTC](https://connective.celigo.com/t/flatten-a-record-with-an-array-of-objects-into-multiple-records/6006/5 "2026-01-20T20:40:36Z")

</div>

Thanks! That worked great!
