Skip to main content

Schema Transform

Apply custom JavaScript transformations to modify export data format and structure.

Overview

Transform functions allow you to customize how processed document data is formatted before export. Write plain JavaScript functions that convert the standard JSON format into your desired output format.

Function Requirements

Input Format

Your function receives the standard JSON export object containing all extracted field data according to your field template structure.

Return Format

The function must return a string-formatted object in one of these formats:

  • JSON - Structured data as JSON string
  • XML - Formatted XML document string
  • Excel - Excel file format string
  • CSV - Comma-separated values string
  • Plain Text - Custom text format string

Writing Transform Functions

Basic Structure

function transform(data) {
// Your transformation logic here
return formattedString;
}

Accessing Field Data

The input data object contains all extracted fields organized according to your field template structure. Reference fields using their name_id values.

Output Examples

CSV Transform:

function transform(data) {
const headers = "Invoice,Date,Amount\n";
const row = `${data.invoice_number},${data.invoice_date},${data.total_amount}`;
return headers + row;
}

XML Transform:

function transform(data) {
return `<invoice>
<number>${data.invoice_number}</number>
<date>${data.invoice_date}</date>
<amount>${data.total_amount}</amount>
</invoice>`;
}

Integration with Connectors

Export Delivery

  • Connector compatibility - Transform output is sent via configured connectors
  • Format detection - Connectors receive the transformed string format
  • Error handling - Transform failures prevent export delivery

Validation Integration

  • Pre-validation - Documents must pass validation before transformation
  • Field availability - Only validated fields are available in transform function
  • Error prevention - Validation errors block transform execution

Best Practices

Function Design

  1. Error handling - Include try-catch blocks for robust transformation
  2. Data validation - Check for required fields before processing
  3. Format consistency - Ensure output format matches connector expectations
  4. Performance - Keep transforms efficient for large-scale processing

Testing

  1. Sample data - Test transforms with representative document data
  2. Edge cases - Handle missing or null field values gracefully
  3. Format validation - Verify output format is correct for target systems
  4. Integration testing - Test complete flow from extraction through export