# Create X Amount of Connected Records Based on a Number Field

> The following demonstration will show you how to create X amount of connected Child records based on a Number field in the Parent table.

Source: https://tadabase.com/docs/snippets/create-x-amount-of-connected-records-based-on-a-number-field  
Status: Not yet re-checked. Moved from our previous help site and not yet re-checked against the current product. Last edited Sep 20, 2024.

![Screenshot for “Create X Amount of Connected Records Based on a Number Field”](https://tadabase-docs-assets.s3.amazonaws.com/uploads/images/gallery/2022-10/scaled-1680-/image-1665331907983.png)

The following demonstration will show you how to create X amount of connected Child records based on a Number field in the Parent table.

**Step 1**

**Download the custom JavaScript pipe. Set up the parameters as seen below in a run serverside JavaScript call.**

![Screenshot for “Create X Amount of Connected Records Based on a Number Field”](https://tadabase-docs-assets.s3.amazonaws.com/uploads/images/gallery/2022-10/scaled-1680-/image-1665328571890.png)

**Step 2**

**Add the following code to the request tab. Update your API keys.**

```
var appId = 'APP_ID';
var apiKey = 'API_KEY';
var apiSecret = 'API_SECRET';
var childTable = 'CHILD_TABLE_ID';
var childJoinFieldId = 'field_ID';

var parentRecordId = '{parentRecordId}';
if ('{flag}' === '{flagValue}') {
    for (let i = 0; i < {
            qty
        }; i++) {
        var settings = {
            "method": "POST",
            "headers": {
                "X-Tadabase-App-id": appId,
                "X-Tadabase-App-Key": apiKey,
                "X-Tadabase-App-Secret": apiSecret,
            }
        };
        var data = {
            [childJoinFieldId]: parentRecordId
        }
        var request = settings;
        request.method = 'POST';
        request.payload = data;
        UrlFetchApp.fetch("https://api.tadabase.io/api/v1/data-tables/" + childTable + "/records", request);
    }
}
```

![Screenshot for “Create X Amount of Connected Records Based on a Number Field”](https://tadabase-docs-assets.s3.amazonaws.com/uploads/images/gallery/2022-10/scaled-1680-/image-1665329063831.png)

**Step 3**

**Still editing the request-response, we will now update the child table ID and the field ID. The location of these values can be found here in the image below.**

![Screenshot for “Create X Amount of Connected Records Based on a Number Field”](https://tadabase-docs-assets.s3.amazonaws.com/uploads/images/gallery/2022-10/scaled-1680-/image-1665330080869.png)

**Step 4**

**Add the following table rule to your parent table.**

![Screenshot for “Create X Amount of Connected Records Based on a Number Field”](https://tadabase-docs-assets.s3.amazonaws.com/uploads/images/gallery/2022-10/scaled-1680-/image-1665330525427.png)

**Original Community post:**

[Create X amount of connected records based on a Number field - Community Discussions / Pipes - Tadabase Community](https://community.tadabase.io/t/create-x-amount-of-connected-records-based-on-a-number-field/1477)

> **Note:** Please see the original community post for further customization options.
