Server-Side Scripting for Plex
Extend Plex with Custom Logic
DataMagik Script Engine lets you write powerful server-side scripts that run within the DataMagik platform. Transform data, validate inputs, call external APIs, and build custom business logic - all with full access to Plex data.
Why Use the Script Engine?
When standard configurations aren't enough, scripts give you unlimited flexibility.
π§ Custom Business Logic
Implement complex business rules that go beyond what's possible with standard configuration. Calculate custom values, enforce validation rules, or implement industry-specific logic.
π Data Transformation
Transform data between formats, clean up inputs, merge data from multiple sources, or reshape data for external systems.
π External API Integration
Call external REST APIs, web services, or third-party systems directly from your scripts. Get data from external sources or push updates to other platforms.
β‘ Real-Time Processing
Scripts execute in real-time when triggered. Process data instantly as users interact with Plex screens or when events occur.
Script Capabilities
Everything you need to build powerful integrations and automations.
π Plex Data Access
Read and write Plex data directly from your scripts. Query data sources, update records, and interact with Plex APIs.
Query Plex data sources
- Run queries against any Plex data source with parameters
Call Plex APIs
- Execute Plex web service APIs directly
Read screen context
- Access data from the current Plex screen
Write back to Plex
- Update Plex records through standard APIs
π HTTP Requests
Make HTTP calls to external systems. Integrate with REST APIs, webhooks, and web services.
GET, POST, PUT, DELETE
- Full HTTP method support
Custom headers
- Set authentication tokens, content types, and custom headers
JSON/XML handling
- Parse and generate JSON and XML payloads
Error handling
- Catch and handle HTTP errors gracefully
π Secure Credential Storage
Store API keys, passwords, and tokens securely. Reference credentials in your scripts without exposing sensitive values in code.
Encrypted storage
- Credentials are encrypted at rest
Named references
- Reference credentials by name in scripts
Access control
- Control which scripts can use which credentials
Audit logging
- Track credential usage
π Logging & Debugging
Built-in logging helps you develop, test, and troubleshoot your scripts.
Console logging
- Write debug messages during execution
Execution history
- View past script runs and their outputs
Error details
- Full stack traces when errors occur
Performance metrics
- See execution times and resource usage
π¦ Built-In Libraries
Common utilities are available out of the box. No need to reinvent the wheel.
Date/time handling
- Parse, format, and calculate dates
String manipulation
- Format, parse, and transform text
Math functions
- Calculations, rounding, and number formatting
Data validation
- Validate emails, phone numbers, and other formats
Encoding/decoding
- Base64, URL encoding, and more
The Script Editor
A modern, developer-friendly environment for writing scripts.
π» Modern Code Editor
Write scripts in a full-featured code editor with syntax highlighting, auto-completion, and error detection. Syntax highlighting for JavaScript Auto-complete for built-in functions Real-time error detection Code formatting Search and replace
βΆοΈ Test & Debug
Run scripts directly in the editor with test data. See results instantly without deploying. Run with sample data View console output Inspect return values Step through errors
π Documentation & Help
Built-in documentation for all available functions, objects, and APIs. Never leave the editor to find help. Function reference Code examples API documentation Best practices
How Scripts Get Triggered
Multiple ways to execute your scripts based on your needs.
π±οΈ From Plex Screens
Use DataMagik Automate to add buttons to Plex screens that trigger scripts. Users click and scripts execute with the current screen context.
π In Document Templates
Call scripts from document templates to calculate values, fetch additional data, or transform content before generation.
π Via API
Trigger scripts via HTTP API from external systems. Pass parameters and receive results.
β° On Schedule
Schedule scripts to run automatically at specific times or intervals. Perfect for batch processing and scheduled integrations.
π From n8n Workflows
Call scripts as steps within n8n workflows. Combine visual workflow automation with custom script logic.
Example Use Cases
See what you can build with the Script Engine.
π·οΈ Custom Barcode Generation
Generate complex barcode values that combine multiple fields with checksums and formatting rules.
Example: Create GS1-128 barcodes with application identifiers, dates, and serial numbers concatenated with proper formatting.
π° Custom Pricing Calculations
Calculate prices based on complex rules - volume discounts, customer tiers, material costs, and market factors.
Example: Calculate quoted price based on material weight, finishing costs, customer discount tier, and current steel market index.
π§ Smart Notifications
Send intelligent notifications to the right people based on complex conditions and escalation rules.
Example: When a quality hold exceeds 24 hours, escalate notification to quality manager. After 48 hours, include plant manager.
π ERP Synchronization
Keep external ERP or accounting systems in sync with Plex data through real-time API calls.
Example: When an invoice is posted in Plex, create matching invoice in QuickBooks via API.
π Custom Data Validation
Validate data against complex business rules before allowing actions to proceed.
Example: Before releasing a shipper, verify all containers have valid weights, all required documents are attached, and customer credit is approved.
π‘οΈ IoT Data Processing
Process data from sensors, PLCs, or IoT devices and write results to Plex.
Example: Receive temperature readings from sensors, calculate averages, and log to Plex quality records.
π Complex Report Generation
Aggregate and transform data for complex reports that can't be done with standard queries.
Example: Generate a customer scorecard combining on-time delivery, quality PPM, and cost savings across all programs.
π Data Migration & Cleanup
Batch process records for data cleanup, migration, or mass updates.
Example: Standardize phone number formats across all customer records.
Script Example
Here's what a simple script looks like.
Example: Get customer info and call external API
// Get customer data from current screen context
const customerId = context.screen.customerId;
// Query Plex for customer details
const customer = await plex.query('Customer_Get', {
Customer_Key: customerId
});
// Call external CRM API
const crmResponse = await http.post('https://api.crm.com/customers', {
headers: {
'Authorization': credentials.get('crm-api-key'),
'Content-Type': 'application/json'
},
body: {
name: customer.Customer_Name,
code: customer.Customer_Code,
email: customer.Email
}
});
// Return result
return {
success: true,
crmId: crmResponse.id,
message: 'Customer synced to CRM'
};
Security & Governance
Enterprise-ready security for your scripts.
π
Permission Control
- Control who can create, edit, and execute scripts ποΈ
Execution Audit
- Full audit trail of all script executions β±οΈ
Timeout Limits
- Scripts have execution time limits to prevent runaway processes π«
Sandboxed Execution
- Scripts run in isolated environments π
Resource Monitoring
- Track script resource usage and performance
Ready to Extend Plex with Custom Scripts?
Get started with DataMagik Script Engine and build the integrations your business needs.