Skip to main content

Overview

ERPLite provides a low-code scripting environment for advanced users to write JavaScript for data manipulation, calculations, and dynamic logic.

JavaScript

Write standard JavaScript code

Libraries Included

Lodash and Luxon pre-loaded

Test Environment

Test scripts with mock data

Data Access

Access all task and user data

Supported Libraries

LibraryPurposeDocumentation
LodashUtility functions for arrays, objects, stringslodash.com
LuxonDate/time manipulation and formattingmoment.github.io/luxon

Where to Use Scripts

Scripts can be used anywhere you see the JS icon in ERPLite:
  • Component value bindings
  • Automation conditions
  • Validation expressions
  • Computed values
  • Action configurations

Writing Scripts

Basic Syntax

Scripts must return a value using the return statement:
// Combine first and last name
return task.data.first_name + " " + task.data.last_name

Accessing Data

// User data fields
task.data.field_name

// System data
task.taskId
task.status
loggedInUser.name
loggedInUser.role

Testing Scripts

1

Open Script Editor

Click the JS icon to open the script editor
2

Write Your Code

Enter your JavaScript code
3

Update Mock Data

Click Update Mock Data to set test values
4

Run Test

Click the Run button to execute
5

Check Output

Verify the result in the output box
The output type must match what the component expects. A number field requires a number output.

Examples

String Manipulation

// Combine names
return task.data.first_name + " " + task.data.last_name

// Uppercase text
return task.data.customer_name.toUpperCase()

// Extract initials
return task.data.first_name[0] + task.data.last_name[0]

Working with Arrays (Lodash)

// Get first element
let words = ['sky', 'wood', 'forest'];
return _.first(words);  // 'sky'

// Get last element
return _.last(words);  // 'forest'

// Sum numbers
let prices = [10, 20, 30];
return _.sum(prices);  // 60

Date/Time (Luxon)

// Current date/time in ISO format
return DateTime.now().toISO()

// Current time in specific timezone
return DateTime.local({ zone: 'America/New_York' }).toString()

// Format a date
return DateTime.fromISO('2024-01-15T10:30:00Z').toLocaleString()

// Add days to a date
return DateTime.fromISO(task.data.start_date).plus({ days: 7 }).toISO()

Calculations

// Calculate total with tax
const subtotal = task.data.quantity * task.data.unit_price;
const tax = subtotal * 0.1;
return subtotal + tax;

// Calculate percentage
return (task.data.completed / task.data.total) * 100;

Conditional Logic

// Return different values based on condition
if (task.data.order_amount > 1000) {
  return "Premium Order";
} else {
  return "Standard Order";
}

// Ternary operator
return task.data.is_urgent ? "URGENT" : "Normal";

Best Practices

Complex logic is harder to debug. Break into smaller pieces if needed.
Always check if data exists before using it:
return task.data.name || "Unknown"
Name variables clearly for better readability.
Test with empty values, nulls, and boundary conditions.

For AI Agents

Script Context Variables

VariableDescription
taskCurrent task object
task.dataUser-defined data fields
task.taskIdTask identifier
task.statusCurrent task status
loggedInUserCurrent user object
loggedInUser.nameUser’s name
loggedInUser.roleUser’s role
loggedInUser.teamUser’s team
_Lodash library
DateTimeLuxon DateTime class

Script Execution

interface ScriptConfig {
  script: string;
  expectedOutputType: 'string' | 'number' | 'boolean' | 'object' | 'array';
}

// Scripts are executed in a sandboxed environment
// Return value must match expected type

UI Components

ComponentLocationPurpose
ScriptEditor/src/components/LowCode/ScriptEditor/Code editing
MockDataEditor/src/components/LowCode/MockData/Test data configuration
ScriptRunner/src/components/LowCode/Runner/Script execution

Error Handling

Scripts that throw errors will:
  1. Log the error to automation logs
  2. Return undefined or fail the action
  3. Display error message in test mode