Sep 14, 2021 03:34 PM
I’m not too sure where I’m going wrong. The Javascript examples I’ve read indicate that this should work, but Airtable isn’t processing them as I’d hoped - and judging from the results I’ll need to modify my script somehow.
Although the Automation triggers at the correct local time, it certainly doesn’t pass the local time as an input into the script - which isn’t a problem so long as we can easily process it to the correct time within the script, which is where I’m stuck.
//Trigger executes 7am daily and provides the _input_date to the script, but it is using yesterdays date (even though Airtable trigger states it is using local time?), so attempting to align it with local time via JS below
let rightNow = input.config()._input_date;
var date = new Date(rightNow);
let today = new Date()
let string = today.toLocaleDateString()
let correct = new Date(string)
console.log(date.getTimezoneOffset());
console.log(date.toLocaleTimeString('en-AU'));
console.log(correct)
Appreciate any help. This is messing with me big time. :face_with_raised_eyebrow:
Solved! Go to Solution.
Sep 22, 2021 08:49 AM
Very clever solution, @kuovonne! Not sure why it didn’t occur to me sooner to use a formula, but it works very well.
Because of how the API that I’m currently using is returning the time difference and how I’m using that difference in my script, I tweaked the output and added some things to return the same format as the API. In the screenshot below from my [Setup]
table, left is the API return, and right is the output from my tweaked formula.
"-0" & ABS(DATETIME_DIFF(
DATETIME_PARSE(
DATETIME_FORMAT(
SET_TIMEZONE(NOW(), "America/Los_Angeles"),
"YYYY-MM-DD-HH-mm"
),
"YYYY-MM-DD-HH-mm"
),
NOW(),
"hours"
)) & ":00"
Sep 24, 2021 02:39 PM
That’s a great workaround. Still frustrating that I need to create two new fields to support a workflow, I wish I could do this all via the Automation Script routine without the need for an external reference/field.