Skip to main content

Execution Contexts

Facilio Script doesn't run on its own — the platform invokes your script when a triggering event happens (a record changes, a button is pressed, an email is rendered, a schedule fires, etc.). The execution context is the place from which the script is invoked, and it determines what data the platform passes in.

Where scripts run#

Facilio Script runs in two kinds of contexts:

Record-bound contexts — the script is triggered by an event on a specific record, and the platform passes that record in as a Map.

  • Workflows — invoked on record create / update / delete
  • State flows — invoked on state transitions
  • Custom buttons — invoked when a user clicks a button on a record
  • Notifications — invoked when a notification is composed
  • Approval processes — invoked at each approval step
  • Functions — invoked from other scripts or the API on a record

Standalone contexts — the script runs without a triggering record.

  • Schedulers — invoked on a cron schedule

Record-bound contexts — function signature#

For all record-bound contexts above, the function follows a fixed contract:

  • Return type: void
  • Function name: execute_script
  • Parameter: a single Map whose name is the link name of the triggering module

The platform passes the triggering record as that Map, so you access record fields with dot notation (workorder.subject, workorder.priority.id, etc.).

void execute_script(Map <moduleLinkName>) {    // script logic - access fields via <moduleLinkName>.<fieldName>}

Examples by module#

The parameter name is the link name of the module the script is bound to. Find the link name under Setup > Customization > Modules > [Your Module] > Properties in Facilio.

// Bound to the work order modulevoid execute_script(Map workorder) {    log workorder.subject;
    if (workorder.priority.id == 955) {        log "urgent";    }}
// Bound to a custom module called "custom_invoices"void execute_script(Map custom_invoices) {    log custom_invoices.invoiceNumber;
    if (custom_invoices.total > 1000) {        log "high value";    }}
// Bound to the asset modulevoid execute_script(Map asset) {    if (asset.category.name == "Chiller") {        log asset.name;    }}

Reading the record Map#

The Map parameter contains the triggering record. Fields are accessed via dot notation; lookups (foreign keys) are nested maps holding at minimum { id }.

void execute_script(Map workorder) {    log workorder.id;             // record id    log workorder.subject;        // plain field    log workorder.priority.id;    // picklist - dotted access    log workorder.assignedTo.id;  // user lookup    log workorder.siteId;         // siteId is a Number, not a lookup}

To fetch the full lookup record (anything beyond { id }), do a separate Module(...).fetchFirst([...]) — see Module functions.

Schedulers — standalone signature#

A scheduler script is not triggered by a record, so it takes no parameters:

  • Return type: void
  • Function name: execute_script
  • Parameters: none
void execute_script() {    openWOs = Module("workorder").fetch({        criteria: [status == "Open"]    });
    if (openWOs != null) {        for each wo in openWOs {            log wo.subject;        }    }}

Inside the body, fetch the records you need explicitly via Module(...).fetch(...). See Schedule functions for creating and managing schedules.

For the full language reference, see Syntax & Grammar.