Help

Save the date! Join us on October 16 for our Product Ops launch event. Register here.

Create Records based on a number field in a different table

Topic Labels: Scripting extentions
1180 1
cancel
Showing results for 
Search instead for 
Did you mean: 
Amanda_Lubow
4 - Data Explorer
4 - Data Explorer

I’m trying to create a certain number of new records in a table based on a number in another table.

For example, if the # Field in Table A is 4, then I want to create 4 new records in Table B.

Is this possible? Any idea how I’d do it with either Scripts or Automations?

1 Reply 1
KVachon
6 - Interface Innovator
6 - Interface Innovator

Hey there!

  1. You can create a linked field between Table A and Table B (we will call it Created Records Link)
  2. Then create an automation triggered on “When record matches condition” that looks at your # Field in Table A. (you can use any trigger you’d like)
  3. Create a “Run a Script” step
  4. Create two input variables:
  • numberOfRecords: look at the first step at the # Field
  • linkedRecordId: look at the first step and choose the Record ID

Then drop in this script:

let inputs = input.config();
let numberOfRecords = inputs.numberOfRecords;
let linkedRecordId = inputs.linkedRecordId;
let recordsTable = base.getTable("Table B");

// Create three records in the Table B table linked to Table A
    for (let i = 1; i < numberOfRecords + 1; i++) {
    let recordId = await recordsTable.createRecordAsync({
    "Name": "Test " +[i],
    "Created Records Link": [{id: linkedRecordId}],
    })
};

This will create the number of records that you identified in Table A # field in Table B. In this example I just created them with the name “Test” and the record number.