Create multiple linked records with a button

Hi

I would like to be able to create multiple linked records in one “run”.

I do a lot of videos for lectures and have a base has with a “productions” table and a “projects” table.

I want to be able to

  • add a button in the “projects” table that runs a script
  • the script should ask me how many new records to create in the “productions” table.
  • and then create the records linked to the project

This would help me when 1 projects has 30 productions.

And because a higher demand for remote learning I get many request for many videoes - so time saved on place it time used in another:)

Thanks!

Do the newly created [Productions] records need any information filled out other than the field linking it to the [Projects] table? If not, then you could use the following process:

  • Use an input to get the project (either from running the script normally or from a button click):
    const project = await input.recordAsync("Pick a project", projectTable)
  • Use another input to get the number of productions to add:
    const number = await input.textAsync("How many productions to add")
  • Use a loop to create the values for the new productions records:
    const values = []
    while (i < number) {values.push({fields: {"The name of the link field": {id: project.id}}})}
  • Create the new productions records:
    const newRecords = await productionsTable.createRecordsAsync(values)

Thanks Kamille!

I would just need to create the linkeds productions.

I have tried but I can’t get it to work (I’m a no-coder :grin:) I have just copied it but I don’t know which text I should change to connect it to my base.

This it how I have written it:

const project = await input.recordAsync("Pick a project", ProjectsTable)

const number = await input.textAsync("How many productions to add")

const values = []

while (i < number) {values.push({fields: {"Projects": {id: project.id}}})}

const newRecords = await ProductionsTable.createRecordsAsync(values)

To write to a Record Link field, the format has to be an array. So try the following instead:

while (i < number) {values.push({fields: {"Projects": [{id: project.id}]}})}