The Invoice Export hook fires just before an invoice is sent to an external system — typically an accounting platform like QuickBooks or NetSuite, or an EDI partner. Like Shipment Notification, this hook exposes both the invoice and the parent order, so you can use order context to shape the invoice.
These rules are about formatting and routing — making sure the invoice has the right structure, codes, and metadata for the destination system.
Add accounting GL codes
rule "Set GL codes by category"
when
order.custom.tier is "vip"
then
set invoice.custom.gl_revenue_code to "4100"
set invoice.custom.gl_cost_code to "5100"
end
when
order.custom.tier is "wholesale"
then
set invoice.custom.gl_revenue_code to "4200"
set invoice.custom.gl_cost_code to "5200"
end
when
order.custom.tier is "standard" or order.custom.tier is blank
then
set invoice.custom.gl_revenue_code to "4000"
set invoice.custom.gl_cost_code to "5000"
end
end
Different customer tiers map to different general-ledger accounts. Setting them at export time means your accounting system files the revenue under the right account automatically.
Tag invoices for region-specific tax rules
rule "EU tax flag"
when
order.shipping_address.country is "DE"
or order.shipping_address.country is "FR"
or order.shipping_address.country is "IT"
or order.shipping_address.country is "ES"
or order.shipping_address.country is "NL"
then
set invoice.custom.tax_jurisdiction to "EU"
set invoice.custom.requires_vat to true
end
when
order.shipping_address.country is "GB"
then
set invoice.custom.tax_jurisdiction to "UK"
set invoice.custom.requires_vat to true
end
end
Different jurisdictions need different tax handling — flag the invoice so the accounting system applies the right rules.
Suppress invoices for test orders
rule "Don't export test invoices"
when
order.notes contains "TEST"
or order.custom.tag is "test"
then
reject invoice
end
end
Test orders shouldn’t generate accounting records. Rejecting the invoice in this hook prevents the export — the invoice still exists in DropStream, but doesn’t reach the accounting system.
Add customer reference
rule "Add customer reference"
when
order.external_customer_id is_not blank
then
set invoice.custom.customer_reference to order.external_customer_id
set invoice.custom.customer_email to order.customer_email
end
end
Many accounting systems need a customer ID for matching. Pull it from the order onto the invoice.
Calculate and set totals
rule "Set invoice totals from order"
set invoice.subtotal to order.subtotal
set invoice.shipping_amount to order.shipping_amount
set invoice.tax_amount to order.tax_amount
set invoice.total to order.subtotal + order.shipping_amount + order.tax_amount
end
If your invoice export requires explicit totals separate from the order’s, compute and assign them. Note: this is straightforward when DropStream’s invoice already reflects the order; use it when transformations elsewhere have changed the values.
Add custom fields for ERP integration
rule "Add NetSuite custom fields"
set invoice.custom.netsuite_class to order.shipping_address.country
set invoice.custom.netsuite_department to order.custom.tier
when order.custom.tag is "wholesale" then
set invoice.custom.netsuite_subsidiary to "Wholesale Division"
end
when order.custom.tag is "retail" then
set invoice.custom.netsuite_subsidiary to "Retail Division"
end
end
When the destination ERP needs custom fields beyond the standard invoice schema, populate them in this hook from order data.
Format invoice number for external system
rule "Format invoice number"
set invoice.custom.external_number to
"DS-" & order.id & "-" & invoice.id
end
Some systems require specific invoice number formats. Compute and set the formatted string at export time.
Fail if required custom field missing
rule "Fail invoices without GL codes"
when
invoice.custom.gl_revenue_code is blank
then
fail invoice with "Invoice for order " & order.id & " has no GL revenue code; check tier rules"
end
end
Defensive: catch invoices missing critical accounting metadata before they reach the destination system. Failing surfaces the issue immediately rather than letting bad data flow downstream.
Tips
-
You can read both records. Use
invoice.Xfor invoice-specific fields (GL codes, formatting, totals); useorder.Xfor context (tier, region, customer details, tags from Order Import rules). - Set the custom fields the destination system needs. Most accounting integrations expect specific fields — know what your destination needs and populate them here. The values often come from order tags or categories that earlier rules already set.
- Reject is your “skip export” switch. Rejecting an invoice in this hook prevents the export but doesn’t delete the invoice from DropStream. It stays available for reference and reporting.
- Order Import + Invoice Export are a pipeline. Rules at the Order Import hook tag and categorize orders; rules here read those tags and translate them into invoice fields. Keep the categorization logic at Order Import and the formatting logic here — that separation makes both sets easier to maintain.
Comments
Please sign in to leave a comment.