Skip to content

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.
  1. Open the script in the editor and choose Add config parameter in the Config parameters panel.
  2. 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.
  3. In the script, replace the typed-in value with mash.config.get("DEST_FOLDER").
  4. Save the script.
  5. Attach it to its trigger (an event, schedule or webhook). A Configuration control appears beside it. Fill in this attachment’s values.
  6. 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.

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") ?? 30
set dryRun to mash.config.get("DRY_RUN") ?? false
set 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."
end
Folder: Filed
Days: 30
Dry run: false
DEST_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.

Good candidates:

  • Where things go. Destination share, folder and archive names.
  • Which fields to read. Field names differ between shares: Customer here, Client there.
  • Switches. A DRY_RUN boolean, or SEND_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.

A few setting names mean something special to Foldr itself:

SettingEffect
MASH_TIMEOUTthe time limit in seconds (appliance only)
MASH_MEMORY_LIMITthe memory limit in megabytes (appliance only, raises only)
MASH_SINGLE_INSTANCEallow one running copy at a time (schedules and queued scripts)
MASH_WEBHOOK_DEBUGshow webhook parameter values in the webhook log

See Limits and Foldr Cloud and appliances.

  • 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).