Apr 21, 2020 08:52 AM
Dear Airtable scripting community,
is it possible to share commonly used functions between different blocks of the same database? Currently I use different script blocks for different purposes and would like to avoid duplicating code between them. Is there a way to achieve that?
Thanks, Stefan
Apr 21, 2020 02:24 PM
For Script Blocks, not by design. There is no include capability that I’m aware of. I have found a way to place script functions into an Airtable table (think function library as a collection of records) and call those functions using eval(). You can see an example of this approach here.
For Custom Blocks, yes. It’s a fully-capable React environment.
Apr 21, 2020 11:52 PM
Thanks a lot for the feedback @Bill.French. I like your creative approach, even though an include capability would have been more convenient :slightly_smiling_face:
Apr 22, 2020 12:36 AM
I minified my personal library of helper functions so that it is easy to copy and paste into new scripts. It takes up very few lines in the editor, and if I need to lookup something I refer back to the file with the pre-minified version.
I still have duplicate code in different scripts, but it makes things manageable.
Apr 22, 2020 01:40 AM
Thanks @kuovonne for this idea! It does not solve the code duplication issue but it definitely helps to have a clearer arrangement of your code so it’s more manageable.
Apr 22, 2020 07:49 AM
And this will become more prevalent as our tools near the imposed ceiling for script block size.
Apr 22, 2020 07:58 AM
Do you know that ceiling might be?
Apr 22, 2020 08:00 AM
I do not know the specific value, but it’s definitely there. I have an ElasticSearch-like indexing library and I had to minify it to get it to run in a script block. Without minification, the script block wouldn’t save complaining that the script was too large.
Apr 22, 2020 09:15 AM
Hi @Stefan_Kunz - we are working on something to solve this issue. DM me for details if interested. Will be able to share in the coming weeks.
Apr 22, 2020 11:28 AM
Thanks @openside - I just sent you a DM.