Help

Share code among different script blocks

Topic Labels: Scripting extentions
3821 9
cancel
Showing results for 
Search instead for 
Did you mean: 
Stefan_Kunz
6 - Interface Innovator
6 - Interface Innovator

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

9 Replies 9

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.

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:

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.

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.

And this will become more prevalent as our tools near the imposed ceiling for script block size.

Do you know that ceiling might be?

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.

openside
10 - Mercury
10 - Mercury

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.

Stefan_Kunz
6 - Interface Innovator
6 - Interface Innovator

Thanks @openside - I just sent you a DM.