← The Protocol Lab — all BIOVIA Pipeline Pilot guides

PilotScript in Pipeline Pilot

The scripting language that turns good protocols into great ones.

Most Pipeline Pilot users get by without ever writing a line of PilotScript. Then they hit a problem no combination of built-in components solves cleanly — a conditional branch, a string manipulation, a dynamic calculation — and they discover scripting. Once you learn it, you use it constantly. Here is everything you actually need to know, explained the way I walk new engineers through it.

Where PilotScript lives in your protocol

PilotScript is not a separate file or editor — it is an expression language you embed directly inside component properties. The main places you will write it:

  • Add Property (Script) component — the most common use. Adds a new property to each record whose value is computed by your script expression.
  • Filter (Script) component — your expression returns true (keep the record) or false (filter it out). Far more flexible than the standard filter UI for complex conditions.
  • Split (Script) component — routes records to different output ports based on an expression. The foundation of conditional branching in protocols.
  • Property default values — script expressions can compute default values for protocol parameters, evaluated once at startup.

Syntax basics — the language in plain English

PilotScript is a simple expression language, closer to Excel formulas than to Python or Java. It evaluates one expression and returns a value. Here are the building blocks:

// Read a property from the current record
value = mol::GetProperty("SampleID")

// String operations
upper   = mol::ToUpper(value)
trimmed = mol::Strip(value)
joined  = "SITE_" + mol::GetProperty("SiteCode") + "_" + value

// Math (always convert strings to numbers first)
count = mol::ToFloat(mol::GetProperty("RecordCount"))
pct   = mol::Round(count / 1000.0 * 100, 2)

// Conditional — ternary is the most common pattern
status = mol::GetProperty("TestResult")
flag   = (mol::ToFloat(status) >= 95.0) ? "PASS" : "FAIL"

// Null guard — check before using optional fields
raw = mol::GetProperty("EndDate")
end = mol::IsNull(raw) ? "N/A" : raw

// Date handling
today     = mol::GetDate()
formatted = mol::DateToString(today, "yyyy-MM-dd")

The five functions used in almost every protocol

FunctionWhat it doesExample
mol::GetProperty(name)Read a property from the current recordmol::GetProperty("BatchID")
mol::SetProperty(name, val)Write / update a property on the recordmol::SetProperty("Flag", "PASS")
mol::ToString(val)Convert any value to a stringmol::ToString(42.5) → "42.5"
mol::ToFloat(val)Convert a string to a decimal numbermol::ToFloat("3.14") → 3.14
mol::IsNull(val)Check if a property is empty or missingmol::IsNull(mol::GetProperty("EndDate"))

Conditional logic patterns

Most of the PilotScript I write boils down to three patterns — a simple ternary, a nested ternary for multiple outcomes, and a multi-property condition:

// Pattern 1: simple pass/fail
result = (score >= 95.0) ? "PASS" : "FAIL"

// Pattern 2: multiple tiers (nested ternary)
grade = (score >= 95.0) ? "A" :
        (score >= 80.0) ? "B" :
        (score >= 65.0) ? "C" : "FAIL"

// Pattern 3: compound condition (AND)
approved = (mol::GetProperty("Status") == "APPROVED" &&
            mol::ToFloat(mol::GetProperty("Score")) >= 90.0)
            ? "YES" : "NO"

// Pattern 4: null-safe math on an optional field
rawCount = mol::GetProperty("Count")
count    = mol::IsNull(rawCount) ? 0.0 : mol::ToFloat(rawCount)
rate     = mol::Round(count / 1000.0, 4)

String manipulation — the most common real-world use

At least 40% of the PilotScript I write at Pfizer is string work: building dynamic file paths, reformatting dates, extracting parts of a code, constructing database keys. Here is the toolkit:

// Build a dynamic output file path from runtime parameters
runDate  = mol::GetProperty("RunDate")   // "2024-01-15"
site     = mol::GetProperty("SiteCode")  // "PFZ-PA"
fileName = "C:\Reports\" + site + "_Batch_" + runDate + ".csv"
mol::SetProperty("OutputPath", fileName)

// Extract a substring — positions are zero-based
batchCode = mol::GetProperty("FullBatchID")  // e.g. "PFZ-2024-001"
year      = mol::Substring(batchCode, 4, 8)  // "2024"
seq       = mol::Substring(batchCode, 9, 12) // "001"

// Replace spaces with underscores
cleaned = mol::Replace(mol::GetProperty("RawLabel"), " ", "_")

// Case-insensitive contains check
isAudit = mol::ContainsNoCase(mol::GetProperty("EventType"), "audit")

// Split a pipe-delimited multi-value parameter into the first item
sites     = mol::GetProperty("SelectedSites")  // "PA|NJ|UK"
firstSite = mol::GetToken(sites, "|", 0)        // "PA"

Common mistakes — and how to avoid them

  • Doing math on a string property without converting it — always wrap numeric-looking strings in mol::ToFloat() or mol::ToInt() before any arithmetic.
  • Not guarding against nulls — a null flowing into a math operation crashes the record processing. Use mol::IsNull() for every optional field.
  • Using == to compare a number when the property is stored as a string — '95.0' == 95.0 is false. Convert first, then compare.
  • Writing logic that works on the first 999 records but fails on record 1000 because of an unexpected format — always test with diverse edge-case data before moving to production.
  • Putting complex business logic entirely in PilotScript when a Python custom component would be more readable, testable and maintainable. PilotScript is for short inline expressions; Python is for algorithms.