Post Processing
Custom Code
Write custom code to transform your extracted data
Custom Code
Custom Code lets you write JavaScript code to transform, clean, and enrich your extracted data. You can format dates, clean numbers, match values, and more. If you're not comfortable writing code, you can use AI to generate it for you.
What is custom code?
Custom code is JavaScript code that runs after DigiParser extracts data from your documents. It can:
- Transform values – Format dates, clean numbers, remove currency symbols
- Calculate fields – Add totals, compute percentages, combine values
- Standardize data – Convert text formats, trim spaces, normalize values
- Enrich data – Fetch additional information from external sources (via HTTP requests)
Where to write code
- Go to Settings → Post Processing.
- Click the Custom Code tab.
- You'll see a code editor with sample code. Write or modify the code there.
Using AI to generate code
If you're not comfortable writing code, you can use AI to generate it:
- In the Custom Code tab, click Ask AI to Write Code.
- Describe what you want the code to do (e.g. "Remove currency symbols from all price fields and convert them to numbers").
- The AI generates code for you.
- Review the generated code, test it, and save if it works.
Testing your code
- Select a document from the dropdown (uses real extracted data from your parser).
- Click Run to test the code.
- Compare the Input Data (left) with Output Data (right) to see what changed.
- If it looks good, click Save to apply it to all future documents.
Common examples
Remove currency symbols
// Remove $ and convert to number
if (data.total) {
data.total = parseFloat(data.total.replace(/[$,]/g, ''));
}
return data;Format dates
// Convert "November 8, 2024" to "2024-11-08"
if (data.invoice_date) {
const date = new Date(data.invoice_date);
data.invoice_date = date.toISOString().split('T')[0];
}
return data;Clean multiple fields
// Clean amounts in multiple fields
if (data.subtotal) {
data.subtotal = parseFloat(data.subtotal.replace(/[$,]/g, ''));
}
if (data.tax) {
data.tax = parseFloat(data.tax.replace(/[$,]/g, ''));
}
if (data.total) {
data.total = parseFloat(data.total.replace(/[$,]/g, ''));
}
return data;Important rules
- You can only modify existing fields – You cannot add new fields that don't exist in your schema
- Field types must stay the same – A number field stays a number, a text field stays text
- Always return data – Your code must end with
return data;
Tips
- Start with AI – Use "Ask AI to Write Code" if you're not sure how to write the code
- Test first – Always test on a sample document before saving
- Keep it simple – Start with basic transformations, then add more complex logic
- Use examples – The code editor includes example code you can modify
Next steps
- Lookup Tables – Match values using reference data
- Data Transformations – Pre-built transformations
How is this guide?