CreateRecord in dynamic Table
# 🤝help
a
Hi. I have a table with different city halls users. For example: - Name: Jose - Telephone: 346666666 - City Hall: Alameda Then I have a Table called AlamedaTable with columns: - Name - Description - Date When user starts a conversation via WhatsApp I get the telephone, get the record from City Hall users and get the City Hall name ("Alameda") I want to insert a record into the Table called AlamedaTable so I have created this code: await {{user.usuarioAyuntamiento[0].Ayuntamiento}}.createRecord({ NombreEvento: 'Arbolada 2024', Descripción: 'Plantar arboles', Fecha: 'Del 27-28 de febrero' }) But createRecord only works if I do this: await AlamedaTable.createRecord({ NombreEvento: 'Arbolada 2024', Descripción: 'Plantar arboles', Fecha: 'Del 27-28 de febrero' }) Anyone knows how can I create a code so I can insert into different tables depending on the name of the City Hall? Hope I have explained my self well. Thanks in advance!!
c
Hi @agreeable-accountant-7248 If you have different tables for various cities, you could do let table = AlamedaTable if(user.city === 'something'){ table = AlamedaOtherTable } then table.createRecord
a
Hi, thnks for your answer. It's a good point but I have 103 city halls so I wold prefer not to do ifs and then, that's why I was lookinf for dynamic table names.
c
@agreeable-accountant-7248 the tables api will be released very soon, you will be able to do that easily. But wouldn't it be easier to just have a column which store the name of the city instead? Involves less work in maintaining
a
Great news about the table api!!!. Finally I did what you say, create a table named events and a columnd with the name of the City Hall so I just add records with the name of each City Hall. Thank you for your help!!