Skip to main content

Hi,

I was hoping I might have some help with an Automation please.

I’ve been working on an Automation that will allow people to submit job requests via a form, and then have these jobs appear on my calendar for my accountant to reference. 

The automation works off a number of fields and a script per below:

When a form is submitted > Run a Script

The script looks at what day it is, and starting at 10:00am in 1h blocks will add jobs to the calendar that day as long as they are before 9:00pm.

Jobs falling after 9:00 pm will be pushed to the next business day, and anything on the weekend is pushed to Monday.

The script also look for a specific job type (floor plans) so that only they count towards the slot number (10:00-11:00am, 11:00-12:00pm etc).

As best I can tell, anything relating to the timezone of the automation and formulas it ties into is set to “Use same time zone for all collaborators” with the zone set to “Australia/Perth”.

However, for some reason the first slot always seems to default to 6:00PM on Airtable. 

I’ve spent some time trying to make sure everything’s done correctly but I feel I might have missed something. I’m using a script that was given to me so there might be something in there that is causing the issue too.

Below is the script and screenshots of the automation and formulas. Any ideas? Your help would be massively appreciated! Note: I don’t personally know how to script.
 

// Floor Plan Auto Scheduler Script
// Schedules 1-hour consecutive time slots starting from 10:00am on booking day
 
const table = base.getTable("Main Database");
const recordId = input.config().recordId;
 
// Safety check
if (!recordId) {
    throw new Error("No recordId provided from automation.");
}
 
// Fetch current record
const record = await table.selectRecordAsync(recordId);
if (!record) throw new Error("Record not found.");
 
// Booking Date
const bookingDateRaw = record.getCellValue("Booking Date");
if (!bookingDateRaw) throw new Error("Booking Date is empty. Script exiting.");
 
const bookingDate = new Date(bookingDateRaw);
 
// Skip weekends: push to Monday if Saturday or Sunday
const day = bookingDate.getDay();
if (day === 6) bookingDate.setDate(bookingDate.getDate() + 2); // Saturday → Monday
else if (day === 0) bookingDate.setDate(bookingDate.getDate() + 1); // Sunday → Monday
 
// Base slot = 10:00am on the adjusted date
const baseSlot = new Date(
    bookingDate.getFullYear(),
    bookingDate.getMonth(),
    bookingDate.getDate(),
    10, 0, 0
);
 
// Fetch all records
const allRecords = await table.selectRecordsAsync({ fields: ""Booking Date", "Product Type (from Link to Product Database)"] });
 
// Filter for same-day Floor Plan records (excluding current one)
const sameDayRecords = allRecords.records.filter(=> {
    if (r.id === recordId) return false;
 
    const rDate = r.getCellValue("Booking Date");
    const productTypes = r.getCellValue("Product Type (from Link to Product Database)");
 
    if (!rDate || !productTypes) return false;
 
    const rd = new Date(rDate);
    const isSameDay =
        rd.getFullYear() === bookingDate.getFullYear() &&
        rd.getMonth() === bookingDate.getMonth() &&
        rd.getDate() === bookingDate.getDate();
 
    const isFloorPlan = productTypes.includes("Floor Plan");
 
    return isSameDay && isFloorPlan;
});
 
// Calculate next available slot
const slotIndex = sameDayRecords.length;
const assignedSlot = new Date(baseSlot);
assignedSlot.setHours(baseSlot.getHours() + slotIndex);
 
// Write back the time slot to current record
await table.updateRecordAsync(recordId, {
    "Time Slot (Start)": assignedSlot
});


 

When a Form is Submitted
Add it to the Calendar
Job created at Date/Time
Booking Date for Calendar (9:00pm deadline)
Time Slot Start (For Calendar Automation)
Time Slot End (For Calendar Automation)
Example Order (note 9:51am entry results in 6:00pm slot)

 

Hey ​@C-B_2021,

This is probably due to time zone issues. You might want to check out Kouvonne’s answer in this other similar post.

Mike, Consultant @ Automatic Nation


@C-B_2021 

This is a bit outdated because the date/time fields have recently changed in Airtable, but my sample time zone base & YouTube video might help you get a better understanding of the nonstandard ways that Airtable handles time zones, and how you can use offsets to get the times you’re looking for: Time Zones: Working with multiple different time zones in Airtable

Hope this helps!

If you have a budget and you’d like to hire the best Airtable consultant to help you with this or anything else that is Airtable-related, please feel free to contact me through my website: Airtable consultant — ScottWorld

 


Does this look right?

If so, I’ve pasted the code below.  I forced the date creation to be UTC, set it to 2am UTC which is 10am Perth, and then added an offset at the end.  There’s probably a more elegant way to do it but this seems to work fine

 

// Floor Plan Auto Scheduler Script
// Schedules 1-hour consecutive time slots starting from 10:00am on booking day

const table = base.getTable("Main Database");
const recordId = input.config().recordId;

// Safety check
if (!recordId) {
throw new Error("No recordId provided from automation.");
}

// Fetch current record
const record = await table.selectRecordAsync(recordId);
if (!record) throw new Error("Record not found.");

// Booking Date
const bookingDateRaw = record.getCellValue("Booking Date");
if (!bookingDateRaw) throw new Error("Booking Date is empty. Script exiting.");

const bookingDate = new Date(bookingDateRaw);

// Skip weekends: push to Monday if Saturday or Sunday
const day = bookingDate.getDay();
if (day === 6) bookingDate.setDate(bookingDate.getDate() + 2); // Saturday → Monday
else if (day === 0) bookingDate.setDate(bookingDate.getDate() + 1); // Sunday → Monday

// Base slot = 10:00am on the adjusted date
const baseSlot = new Date(Date.UTC(
bookingDate.getFullYear(),
bookingDate.getMonth(),
bookingDate.getDate(),
2, 0, 0 // 2am UTC = 10am Perth
));

// Fetch all records
const allRecords = await table.selectRecordsAsync({ fields: ("Booking Date", "Product Type (from Link to Product Database)"] });

// Filter for same-day Floor Plan records (excluding current one)
const sameDayRecords = allRecords.records.filter(r => {
if (r.id === recordId) return false;

const rDate = r.getCellValue("Booking Date");
const productTypes = r.getCellValue("Product Type (from Link to Product Database)");

if (!rDate || !productTypes) return false;

const rd = new Date(rDate);
const isSameDay =
rd.getFullYear() === bookingDate.getFullYear() &&
rd.getMonth() === bookingDate.getMonth() &&
rd.getDate() === bookingDate.getDate();

const isFloorPlan = productTypes.includes("Floor Plan");

return isSameDay && isFloorPlan;
});

// Calculate next available slot
const slotIndex = sameDayRecords.length;
const assignedSlot = new Date(baseSlot.getTime() + slotIndex * 60 * 60 * 1000);


// Write back the time slot to current record
await table.updateRecordAsync(recordId, {
"Time Slot (Start)": assignedSlot
});

 


Reply