It’s been awhile since you posted, and I hope you have gotten your code to work. However, if you still need help, here are some thoughts …
Are you sure that the input variable JOB is an array?
If you do a console.log(jobId)
does it show what you expect?
This line looks strange. You do not need to await the base.getTable
command. You want
let applicationsTable = base.getTable("Applications");
One way to speed up scripts is to indicate what field values you want in selectRecordsAsync()
. Returning only the fields you need can make for faster execution, especially if there are many fields. However, I suspect that this is not the root of your problem.
This line also looks strange. Later on you declare a function named filterOlderApplications
. However, here you are not actually calling the function, and you are not passing the record to the filterOlderApplications
function.
I suspect you want something more like
.filter(record => filterOlderApplications(record))
Have you check if your filter is actually working as expected? Or is it not actually filtering out anything?
There are a few places where your coding style is a bit wordy, and things could be tightened up, but none of those places should be causing a major performance hit.
It’s been awhile since you posted, and I hope you have gotten your code to work. However, if you still need help, here are some thoughts …
Are you sure that the input variable JOB is an array?
If you do a console.log(jobId)
does it show what you expect?
This line looks strange. You do not need to await the base.getTable
command. You want
let applicationsTable = base.getTable("Applications");
One way to speed up scripts is to indicate what field values you want in selectRecordsAsync()
. Returning only the fields you need can make for faster execution, especially if there are many fields. However, I suspect that this is not the root of your problem.
This line also looks strange. Later on you declare a function named filterOlderApplications
. However, here you are not actually calling the function, and you are not passing the record to the filterOlderApplications
function.
I suspect you want something more like
.filter(record => filterOlderApplications(record))
Have you check if your filter is actually working as expected? Or is it not actually filtering out anything?
There are a few places where your coding style is a bit wordy, and things could be tightened up, but none of those places should be causing a major performance hit.
Hello @kuovonne,
Thank you for taking the time to read my post and suggest some optimizations.
Actually, the code was working on some records but failing sometimes.
Indeed the script might be shortened and refactored a bit for elegance but… as you said, nothing that should be causing a major performance hit.
Our automations started working 100% again on Monday of this week and I think an update was release on Airtable because the “View execution log” panel doesn’t show the CPU limit anymore.
I don’t know if that limit was removed or increased but now it’s working fine… Mystery :grinning_face_with_big_eyes:
About the filter
method on a list, I am pretty sure you can pass a callback function as reference that should accept on parameter (the current item that is being iterated) and return a boolean value. (should be kept in the list or not). (Reference : Array.prototype.filter() - JavaScript | MDN)
Thank you for your help !
Hello @kuovonne,
Thank you for taking the time to read my post and suggest some optimizations.
Actually, the code was working on some records but failing sometimes.
Indeed the script might be shortened and refactored a bit for elegance but… as you said, nothing that should be causing a major performance hit.
Our automations started working 100% again on Monday of this week and I think an update was release on Airtable because the “View execution log” panel doesn’t show the CPU limit anymore.
I don’t know if that limit was removed or increased but now it’s working fine… Mystery :grinning_face_with_big_eyes:
About the filter
method on a list, I am pretty sure you can pass a callback function as reference that should accept on parameter (the current item that is being iterated) and return a boolean value. (should be kept in the list or not). (Reference : Array.prototype.filter() - JavaScript | MDN)
Thank you for your help !
Glad to hear your script is working now.
Yup. You’re right. I am so used to writing anonymous functions that I forgot that they do not need to be anonymous. Thanks for the reminder.