Skip to main content

Share code among different script blocks


Forum|alt.badge.img+1

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

Forum|alt.badge.img+19
  • Inspiring
  • 3264 replies
  • April 21, 2020

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.


Forum|alt.badge.img+1
  • Author
  • Known Participant
  • 11 replies
  • April 22, 2020
Bill_French wrote:

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:


kuovonne
Forum|alt.badge.img+27
  • Brainy
  • 6001 replies
  • April 22, 2020

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.


Forum|alt.badge.img+1
  • Author
  • Known Participant
  • 11 replies
  • April 22, 2020
kuovonne wrote:

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.


Forum|alt.badge.img+19
  • Inspiring
  • 3264 replies
  • April 22, 2020
kuovonne wrote:

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.


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


kuovonne
Forum|alt.badge.img+27
  • Brainy
  • 6001 replies
  • April 22, 2020
Bill_French wrote:

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


Do you know that ceiling might be?


Forum|alt.badge.img+19
  • Inspiring
  • 3264 replies
  • April 22, 2020
kuovonne wrote:

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.


Forum|alt.badge.img+19
  • Inspiring
  • 351 replies
  • April 22, 2020

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.


Forum|alt.badge.img+1
  • Author
  • Known Participant
  • 11 replies
  • April 22, 2020

Thanks @openside - I just sent you a DM.


Reply