Automate timeslot generation

hi,

Exploring Seatable enterprise to see if it can help us build a custom booking/scheduling system.

I have a table “timeslot_types”, with various properties of different kinds of timeslots.

In a different table “timeslots”, I (so far manually) add rows where I only specify the field “time_slot_date” (WITHOUT time component), and through links to the “timeslot_types” table and some link formulas, I can create fields “time_slot_start” and “time_slot_end” (WITH time components, so now viewable in a calendar).

(In the above, I should still include a “timeslot_id” field.)

I’d now like to be able to automate the generation of records in “timeslots”. E.g., for the period between [date_start] and [date_end], create 6 timeslots per day (2 of code01, 4 of code02). So for a period of 60 days, this should result in 60*6 = 360 records.

Is something like this is possible?

There is no no-code way. But with a script, you can achieve what you try to do.

Hi @userroy,

There are probably different ways to achieve what you want, but you won’t be able to avoid a script. Here are few additional thoughts, remarks:

  • I definitely recommend using a Python script because you can create multiple lines at once
  • Will you have to deal with days “off” between [date_start] and [date_end] for which you should not create slots? This could make the script more complex to code
  • There are multiple ways of setting and running your script, as you can see in the documentation. My preference goes to execute it via a button or an automation depending on your needs
  • Depending on whether you want to systematically create time slots for both timeslot_types simultaneously or if you prefer to be able to create time slots for only one timeslot_type, you will respectively either click a button in another “command” table or create a button column in your “timeslot_types” tables so you’ll be able to run the script for each row (meaning each timeslot_type) independently.
  • Whatever your choice, I advise you to create, in the same table as the button column, two date columns[date_start] and [date_end] , which will make the execution of the script more flexible than if you hardcode (write directly in the code) the dates, plus you won’t have to deal with date formats in the code
  • Last but not least, here is how the code might work (for one single timeslot_type):
    • For each day between the values of your [date_start] and [date_end] columns for the current row:
      • For each slot between 1 an the value of slots_daily for the current row:
        • populate an initially empty rows_data array (only setting time_slot_date)
    • Batch create the rows with base.batch_append_rows and store the result in a created_rows variable
    • For each row in your created_rows variable:
      • Feed both a row_id_list and a other_rows_ids_map needed for the base.batch_update_links function (see just below)
    • Batch create the links. If you don’t want to bother with links, you could define a text column like slot_code_name in your “timeslots table”, enter the slot_code value when creating the rows, and define an automation triggered by new lines that will auto link a “timeslots” row with a “timeslot_types” row by comparing slot_code_name (from “timeslots”) and slot_code (from “timeslot_types”)

Hope this helps…

Bests,
Benjamin