Writing Transformations
Transformations are JavaScript functions that receive a record and return a modified version.
Basic Structure
function transform(record) {
// Modify the record
return {
...record,
// your changes
};
}Available APIs
Inside a transformation, you have access to:
| API | Description |
|---|---|
record | The input data record |
context.bridgeId | The bridge this data came from |
context.organizationId | The organization ID |
context.triggerPoint | Which trigger point is active |
console.log() | Logging (visible in execution logs) |
Examples
Add Tags Based on Price
function transform(order) {
const tags = [...(order.tags || [])];
if (order.totalPrice >= 500) {
tags.push('high-value');
}
if (order.totalPrice >= 1000) {
tags.push('vip-order');
}
return { ...order, tags };
}Normalize Address
function transform(order) {
const addr = order.shippingAddress;
if (addr) {
addr.state = addr.state?.toUpperCase();
addr.country = addr.country?.toUpperCase();
addr.zip = addr.zip?.replace(/\s/g, '');
}
return { ...order, shippingAddress: addr };
}Filter Records
Return null to skip a record:
function transform(order) {
// Skip test orders
if (order.tags?.includes('test') || order.customer?.email?.includes('test@')) {
return null;
}
return order;
}Best Practices
- Always spread the original record (
...record) to preserve unmodified fields - Handle null/undefined values defensively
- Keep transformations focused — one concern per transformation
- Use logging for debugging but remove verbose logs in production
- Test with sample data before deploying