Is there still no way to create reusable code in Automations?
I see this thread from 2021, with 6k+ views, which seems to have no resolution (blockchaining is possible in Scripting Apps, but not Automations). Someone must have solutions for this? Copying/pasting seems prehistoric.
Page 1 / 1
Unfortunately, no.
This is one of the Top 20 Reasons why I always encourage everyone to use Make for their automations.
Make allows you to copy and paste modules from one scenario to another, Make allows you to export and import blueprints for backups or portability to other accounts, and best of all, you can use Make’s own internal meta modules to daisy chain scenarios together. There are 44 meta modules that let you control Make, including running other scenarios with dynamic variables.
There is a small learning curve with Make, which is why I created this basic navigation video to help. I also provide the links to a few other Make training resources. For example, to instantly trigger your Make scenarios from Airtable, check out this thread.
Make is a great platform for automations. However, it has its weaknesses as well, the lack of a "merger" module for example is especially annoying, and having to duplicate the "code" 5 times when using a router instead of simply merging is not very elegant.
Make is a great platform for automations. However, it has its weaknesses as well, the lack of a "merger" module for example is especially annoying, and having to duplicate the "code" 5 times when using a router instead of simply merging is not very elegant.
Yeah, I was surprised that they don’t offer a “merge paths” functionality. And they’re not even planning on adding that in the future, either!
Although there are some workarounds for that — you can use variables within the same scenario, or you can pass variables to another scenario. And they also have the “data storage” functionality, where you can create your own tables of data and then pull that info into any scenario.
But still, it would be ideal to have a “merge paths” module.
I am getting some mileage out of the following workaround:
Keep your shared code in a code block
The code block logs its own version every time it gets executed
Leverages a “Logging” table to track which version of the pasted code is being used where
Copy+paste that code block at the bottom of every new automation
So there are a bunch of copies of the shared code floating around within my various Automations, but there’s a mechanism to wrangle older versions and whip the codebase into shape when it gets too sloppy.
Logging table:
Example code block with a few utility functions I’m reusing within my Parse and Search automations:
// Paste this block at the bottom of your automation code // Update the "v0.0.3" semantic version at the bottom of the block any time you change the shared code block // Monitor older shared-code versions via the Logging table, update them as needed
// SHARED CODE STARTS HERE ---------------------------------------------------------
function renderTemplate(template, data) { return template.replace(/\{\{(.*?)\}\}/g, (match, key) => { let value = datavkey.trim()]; return value !== undefined ? value : match; // Preserve original if key not found }); }
function htmlToPlainText(html) { return html.replace(/<\/?a^>]+(>|$)/g, ""); // Removes all HTML tags }
function htmlToMarkdown(html) { // Remove <style> blocks and their content html = html.replace(/<stylee\s\S]*?>[\s\S]*?<\/style>/gi, "");
// Remove <script> blocks and their content (JavaScript) html = html.replace(/<script(\s\S]*?>[\s\S]*?<\/script>/gi, "");
// Convert headers html = html.replace(/<h1>(.*?)<\/h1>/gi, "# $1\n\n"); html = html.replace(/<h2>(.*?)<\/h2>/gi, "## $1\n\n"); html = html.replace(/<h3>(.*?)<\/h3>/gi, "### $1\n\n");
// Convert bold and italic text html = html.replace(/<strong>(.*?)<\/strong>/gi, "**$1**"); html = html.replace(/<b>(.*?)<\/b>/gi, "**$1**"); // Handle <b> as well html = html.replace(/<em>(.*?)<\/em>/gi, "*$1*"); html = html.replace(/<i>(.*?)<\/i>/gi, "*$1*"); // Handle <i> as well
// Convert lists (unordered and ordered) html = html.replace(/<ul>\s*(t\s\S]*?)\s*<\/ul>/gi, (match, content) => { return content.replace(/<li>(.*?)<\/li>/gi, "- $1"); });
html = html.replace(/<ol>\s*(t\s\S]*?)\s*<\/ol>/gi, (match, content) => { let counter = 1; return content.replace(/<li>(.*?)<\/li>/gi, () => `${counter++}. $1`); });
// Convert links html = html.replace(/<a href="(.*?)">(.*?)<\/a>/gi, "/$2]($1)");
// Convert blockquotes html = html.replace(/<blockquote>(.*?)<\/blockquote>/gi, "> $1\n\n");
// Convert horizontal rules html = html.replace(/<hr\s*\/?>/gi, "---\n\n");
// Convert divs to paragraph breaks html = html.replace(/<\/?div>/gi, "\n\n");
// Convert line breaks and paragraphs html = html.replace(/<br\s*\/?>/gi, "\n"); html = html.replace(/<\/p>\s*<p>/gi, "\n\n"); // Ensure proper paragraph spacing html = html.replace(/<\/?p>/gi, ""); // Remove remaining <p> tags
// Remove all remaining HTML tags html = html.replace(/<\/?a^>]+(>|$)/g, "");
// Trim excess whitespace return html.replace(/\n{3,}/g, "\n\n").trim(); }
// let logTable = base.getTable("Logging"); await logTable.createRecordAsync({"actor": `Update from URL`, "action": "track shared code", "description": "code version 0.0.3" });