Article Type: Troubleshooting
Audience: Developers, Solution Architects, Power Users
Module: Data Flows → Script Editor
Applies to Versions: 2024.1+
Developers frequently encounter errors when attempting to use standard JavaScript code in the Fuuz Script Editor. Code that works perfectly in Node.js, browser consoles, or other JavaScript environments fails with "not defined" errors when executed in Fuuz Data Flows.
This commonly occurs when developers copy code from external sources, use AI-generated JavaScript, or attempt to reuse existing transformation logic from other platforms.
ReferenceError: payload is not definedReferenceError: context is not definedReferenceError: input is not definedReferenceError: data is not definedundefinedThe Fuuz Script Editor provides a controlled JavaScript execution environment that differs from standard JavaScript runtimes in several key ways:
| Aspect | Standard JavaScript | Fuuz Script Editor |
|---|---|---|
| Input Data Access | Function parameters, global variables, or imported modules | Pre-defined $ object for payload data |
| Reference Data Access | Passed as parameters or imported from external sources | Context keys become $variableName globals |
| Execution Model | Function invocation with explicit calls | Direct script execution with implicit invocation |
| Output | Return value from function, console.log, or exports | Explicit return statement required |
| Helper Libraries | npm packages, require/import statements | Built-in $functionName() helpers |
| Issue | Cause | Fix |
|---|---|---|
payload is not defined |
Using standard variable naming for input data | Replace payload. with $. |
context is not defined |
Passing context as function parameter | Replace context.key with $key |
| Function not executing | Wrapping code in function without calling it | Remove function wrapper, use direct execution |
Output is undefined |
Missing return statement | Add explicit return { ... } at end |
| Context variable undefined in nested function | Passing context as parameter to helper functions | Access context globals directly: $work_orders |
The following real-world example demonstrates a comprehensive OEE (Overall Equipment Effectiveness) calculation script that was originally written using standard JavaScript patterns. We'll walk through the specific changes required to make it work in the Fuuz Script Editor.
This code was generated using standard JavaScript conventions. It wraps logic in a function and expects payload and context as parameters:
// ❌ THIS CODE WILL FAIL IN FUUZ
function calculateOEE(payload, context) {
// Helper function passes context as parameter
function calculateOEEMetrics(stats, context, isWorkOrder = false) {
if (isWorkOrder) {
const woConfig = context.work_orders[workOrder]; // ❌ context.
const product = context.products[woConfig.product]; // ❌ context.
// ...
}
}
// Process production records using payload parameter
payload.production_records.forEach(record => { // ❌ payload.
// ...
if (!workOrderStats[workOrder]) {
const woConfig = context.work_orders[workOrder]; // ❌ context.
const product = context.products[woConfig.product]; // ❌ context.
// ...
}
});
// Process workUnit history
payload.workUnit_history.forEach(record => { // ❌ payload.
// ...
});
// Calculate metrics passing context to helper
const shiftOEE = Object.values(shiftStats).map(s =>
calculateOEEMetrics(s, context) // ❌ passing context
);
return { /* results */ };
}
ReferenceError: payload is not definedReferenceError: context is not defined| # | Problem | Location in Code | Required Change |
|---|---|---|---|
| 1 | Function wrapper with parameters | function calculateOEE(payload, context) |
Remove function wrapper entirely |
| 2 | Payload access via parameter | payload.production_records |
Change to $.production_records |
| 3 | Context access via parameter | context.work_orders[workOrder] |
Change to $work_orders[workOrder] |
| 4 | Context access via parameter | context.products[woConfig.product] |
Change to $products[woConfig.product] |
| 5 | Passing context to helper functions | calculateOEEMetrics(s, context) |
Remove context parameter; access directly |
| 6 | Helper function signature | function calculateOEEMetrics(stats, context, ...) |
Remove context parameter from signature |
After applying the required transformations, the script executes successfully:
// ✅ THIS CODE WORKS IN FUUZ
// Helper functions remain as internal functions (no context parameter)
function getShift(dateTime) {
const date = new Date(dateTime);
const hour = date.getUTCHours();
if (hour >= 6 && hour < 14) return 'Shift-1';
if (hour >= 14 && hour < 22) return 'Shift-2';
return 'Shift-3';
}
// Helper function accesses context globals directly
function calculateOEEMetrics(stats, isWorkOrder = false) { // ✅ No context parameter
if (isWorkOrder) {
const woConfig = $work_orders[stats.workOrder]; // ✅ $work_orders
const product = $products[woConfig.product]; // ✅ $products
// ...
}
}
// Initialize structures
const workUnitStats = {};
const shiftStats = {};
// Process production records using $ for payload
$.production_records.forEach(record => { // ✅ $.
// ...
if (!workOrderStats[workOrder]) {
const woConfig = $work_orders[workOrder]; // ✅ $work_orders
const product = $products[woConfig.product]; // ✅ $products
// ...
}
});
// Process workUnit history
$.workUnit_history.forEach(record => { // ✅ $.
// ...
});
// Calculate metrics - no context parameter needed
const shiftOEE = Object.values(shiftStats).map(s =>
calculateOEEMetrics(s) // ✅ No context passed
);
// Explicit return statement
return { // ✅ Required return
summary: { /* ... */ },
oee: { byShift: shiftOEE, /* ... */ },
// ...
};
Follow this checklist when converting standard JavaScript to Fuuz-compatible code:
If your code is wrapped in a main function like function processData(payload, context), remove the function declaration and closing brace. The code should execute directly.
// Before:
function processData(payload, context) {
// ... logic ...
return result;
}
// After:
// ... logic ...
return result;
Use find-and-replace to convert all payload access patterns:
| Find | Replace With |
|---|---|
payload. |
$. |
input. |
$. |
data. |
$. |
Context data requires more careful replacement since each key becomes a separate global:
| Find | Replace With |
|---|---|
context.products |
$products |
context.work_orders |
$work_orders |
context.shifts |
$shifts |
context.[keyName] |
$[keyName] |
Remove context from any helper function parameters and their call sites:
// Before:
function calculateMetrics(stats, context, isWorkOrder) {
const config = context.work_orders[stats.workOrder];
// ...
}
const result = calculateMetrics(data, context, true);
// After:
function calculateMetrics(stats, isWorkOrder) {
const config = $work_orders[stats.workOrder]; // Access global directly
// ...
}
const result = calculateMetrics(data, true);
Verify your script ends with an explicit return statement:
// Your processing logic...
// Must have explicit return at the end
return {
summary: productionSummary,
oee: { byShift: shiftOEE, byDay: dayOEE },
insights: { avgOEE: calculatedAverage }
};
When developing JavaScript scripts for the Fuuz platform, keep these important points in mind:
$. (dollar + dot). Context uses $ (dollar only, no dot). This distinction is critical.
Fuuz provides numerous built-in helpers accessible via $functionName(). Before importing external libraries or writing custom utilities, check if a built-in function exists:
$moment() for date/time operations (Moment.js)$groupBy(), $uniq(), $flatten() for array operations$uuid(), $cuid() for ID generation$camelCase(), $snakeCase() for string transformationsWhen using AI tools to generate JavaScript for Fuuz:
$ (not payload)$keyName globals| Version | Date | Editor | Description |
|---|---|---|---|
| 1.0 | 2025-01-01 | Craig Scott | Initial release – Troubleshooting guide for JavaScript conversion |
Fuuz Knowledge Base • © 2025 MFGx, LLC • fuuz.com