Mar 02, 2020 08:20 PM
Um, yeah - it is. But first, a little of the backstory.
As is often the case just when you’ve thought you’ve seen it all, a client asks -
Is it possible to chain blocks and run them sequentially - as one completes, the next one starts?
No, right?
But then she tossed in another requirement -
The computational results from the first block must be available to the next block and sometimes to all subsequent blocks.
Oy! Nothing like a mind-bender for a Monday morning.
This business requirement is daunting – indeed, impossible given the nature of Script Blocks. I’m sure the Airtable folks have pondered this, but as it stands, it’s off the table for now, right? Indeed, Script Blocks are simply not capable … until and unless … you factor in the amazing power of that which Airtable is known and most famous for - simple data/content management with an intimate relationship with integrated script.
Often, it is the alchemy of data and code that spark the most remote possibilities into a new reality.
Simple Workflow Example - a Happiness Survey
Imagine a three-step process asking basic questions about your day. It’s a survey per-se and I’ve embodied the essence of it into a simple table shown below. Each step has a question and a column for answers. Lastly, there’s a final step - Happiness Assessment - that computes your relative happiness based on your answers
The following screenshot shows this three-step process but also displays a very important field showing Block Script in a long text field.
As I mentioned, each step is a question, and each question is presented abstractly in the script using the value in the first column (i.e., Process Step). The final stage in the process is based upon the answers at each step in the survey process.
BlockChaining
To do this elegantly and well, chaining together different script blocks is ideal.
Each script in each process is loaded and executed sequentially. A single “runner” Block orchestrates the execution of each data-based block and it manages the in-memory scope of the results from start to finish.
The final step includes the block shown below which displays the resulting happiness assessment. Note the reference to aRecords
- this is the variable that contains all of the answers gathered from each of the chained blocks.
And the outcome in the block runner reveals this display when all four steps have completed.
Summary
Block chaining is possible. In and of itself, this is an important realization. While my example is super simple and somewhat lame, imagine the incredible solutions that could be built by chaining block scripts together in easily-managed table data.
As I mentioned, it is also possible to manage, share, and aggregate computational results that occur across multiple block segments.
Tell me - is Block Chaining a thing?
Aug 08, 2020 12:43 PM
Hi @Bill.French,
Subject to cross-checking with some of you, this ceiling is at 49999 characters including space :slightly_smiling_face:
Best,
olπ
Oct 15, 2020 07:51 PM
Did anyone write this show and tell article? I would love to dive deeper into the inclusion of libraries into JS. This entire article is an incredible example of your superhero status Bill!
Oct 16, 2020 07:11 AM
Not that I’m aware of one. And unfortunately, that approach won’t work in automation scripts as eval() apparently isn’t supported in that scripting feature as pointed out recently by @kuovonne.
To be clear, I’m not sure its wise for anyone to follow me off the cliff in a Thelma & Louise journey to use tables as script libraries despite the fact that @Jeremy_Oglesby found the concept somewhat compelling in a script block context.
And to ensure there’s no misunderstanding about my original intent - this approach was created to achieve one thing - to provide dynamically changing script logic while the script was running. This objective is a close cousin of the late-binding of libraries.
Setting aside library inclusion, Airtable should make it possible (in all script environments) to manage code in much the way all JavaScript developers do this - by establishing a model for reusable chunks.
I really appreciate the kind comments, but I must warn you - it didn’t end well for Thelma & Louise. There’s a fine line between superheros and super-nut-jobs.
Oct 16, 2020 07:47 AM
Bill just needs to find his Ted to go on his Thelma & Louise adventure :slightly_smiling_face:
We developed an alternative approach we use at Openside/On2Air that allows for reusable snippets/libraries and better overall management of your scripts.
Check out the product here: https://on2air.com/on2air-scripts
Here is a video review of how it works:
Oct 16, 2020 02:33 PM
Hello Openside,your solution is really well designed, I think, but after paying for my Airtable-Pro-Plan, I had a careful compromise to make between several Third-Part-Solutions that offer different additional tools to Airtable without being able to pay them all for my current low to minimal traffic.
I wish you all the best for your offer of excellent Add-Ons for airtable.
oLπ
Oct 16, 2020 02:57 PM
Airtable is not only a very important business tool that must be based on reliable, stable, consistent techniques and must meet the selection criteria of market decision-makers, as @Bill.French teaches us in some of its writings.
It’s also a dream tool that I’ve been waiting for a long time when I found it in a corner of the WEB for a “small lab” that started with Z80s and that today enjoys “As A Service”, “Serverless”, “Micro-Applications”, “Micro-Front-Ends” so don’t hesitate to play Thelma & Louise again from time to time: there is a Audience that loves to follow you on these roads too!
oLπ
Jun 02, 2021 08:46 PM
So I am looking at this solution for Airtable automation since it would mean you could store global functions in a separate table and reference them across your automations.
However, inside Automations I am getting the error “ReferenceError: eval is not defined” despite ‘eval’ showing up as a usable function in the tooltip.
Any ideas? Any workarounds here?
Jun 03, 2021 06:00 AM
There are a few small differences between running a script from scripting app with a button and running a script as an automation. The inability to use eval
in an automation is one of them. Some other differences include using setTimeout
and how fetch
works.
Jun 07, 2021 03:13 PM
Hmm is there a workaround? It’d be great to put global functions into a table that can be referenced directly as code.
Jun 09, 2021 07:52 AM
A CDN + JSON.parse()? But building anything on this sort of functionality seems… unwise.