Use one script for several shares
What it does. Takes a script that has a share’s folder and field names written into it, and turns those into config parameters. The same saved script then runs on the Invoices share with one set of settings and on the Contracts share with another.
What you need.
- The MaSH feature.
- A script that works today for one share.
- Open the script in the editor and choose Add config parameter in the Config parameters panel.
- Give it a name in capitals, such as
DEST_FOLDER, and pick a type: String, Number, Boolean, File, Share, Service account or Custom field. A value typed here is the default. - In the script, replace the typed-in value with
mash.config.get("DEST_FOLDER"). - Save the script.
- Attach it to its trigger (an event, schedule or webhook). A Configuration control appears beside it. Fill in this attachment’s values.
- Attach the same script to another trigger and give it different values.
A value set on an attachment wins over the script’s default. A parameter left empty on the attachment falls back to the default.
Reading settings safely
Section titled “Reading settings safely”mash.config.get returns nothing for a setting that isn’t set. Give every optional one a fallback with ??, and stop with a clear message when a required one is missing:
set dest to mash.config.get("DEST_FOLDER") ?? "Filed"set days to mash.config.get("DAYS") ?? 30set dryRun to mash.config.get("DRY_RUN") ?? falseset required to mash.config.get("DEST_SHARE")
printline "Folder: {{dest}}"printline "Days: {{days}}"printline "Dry run: {{dryRun}}"
if not required printline "DEST_SHARE is not set, so a real run would stop here."endFolder: FiledDays: 30Dry run: falseDEST_SHARE is not set, so a real run would stop here.dest = mash.config.get("DEST_FOLDER") ?? "Filed"days = mash.config.get("DAYS") ?? 30dryRun = mash.config.get("DRY_RUN") ?? falserequired = mash.config.get("DEST_SHARE")
printline("Folder: {{dest}}")printline("Days: {{days}}")printline("Dry run: {{dryRun}}")
if (not required) { printline("DEST_SHARE is not set, so a real run would stop here.")}Folder: FiledDays: 30Dry run: falseDEST_SHARE is not set, so a real run would stop here.In a real automation, replace the last printline with fail "DEST_SHARE is not set on this automation.". fail ends the run with that message, and the run log shows it as Failed.
What to make a setting
Section titled “What to make a setting”Good candidates:
- Where things go. Destination share, folder and archive names.
- Which fields to read. Field names differ between shares:
Customerhere,Clientthere. - Switches. A
DRY_RUNboolean, orSEND_EMAIL. - Thresholds. Days, sizes, counts.
- Addresses and tokens. Never write a token into script text that other people can open. Use a setting, or a Service account setting if your administrator has set one up.
Keep a setting out of the script only if it truly varies. A script with thirty settings is harder to read than two scripts.
Settings that change how a script runs
Section titled “Settings that change how a script runs”A few setting names mean something special to Foldr itself:
| Setting | Effect |
|---|---|
MASH_TIMEOUT | the time limit in seconds (appliance only) |
MASH_MEMORY_LIMIT | the memory limit in megabytes (appliance only, raises only) |
MASH_SINGLE_INSTANCE | allow one running copy at a time (schedules and queued scripts) |
MASH_WEBHOOK_DEBUG | show webhook parameter values in the webhook log |
See Limits and Foldr Cloud and appliances.
Variations
Section titled “Variations”- Read the settings once, at the top. Gather them into variables and guard them there. The rest of the script then reads plain variables.
- A comment block. List each setting and its meaning in a
#comment at the top. The person attaching the script has only the names to go on. - A share-specific tweak. Add a boolean setting, such as
INCLUDE_SUBFOLDERS, rather than copying the script.
Library pages used: Core MaSH (for mash.config).