Create X amount of connected records based on a Number field

In the following video, I will demonstrate how to create X amount of connected Child records based on a Number field in the Parent table.

https://www.screencast.com/t/LV1Zj0W2

NOTE: I added one more Parameter after recording the video called flagValue. This way, you can reuse the Pipe for other Parent/Child tables with different flag values. For example, instead of a hard-coded ‘Yes,’ you can use ‘True’ or any other Radio value you might have.


Here’s the code for the Request. Please remember to update the first 5 lines to your values.

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);
    }
}
2 Likes

Thank you, Chem! That exactly what I needed!

2 Likes

Very useful exactly waht i was looking for!

1 Like