Purchase Inbound Sync: A Single-Strategy Playbook from Marketing Cloud to SQL Server
What This Strategy Solves
In a retail/distribution business, purchase-inbound orders are created and approved in the marketing cloud, and the downstream ERP (built on SQL Server) needs these documents for accounting, inventory, and supplier reconciliation. On the Qeasy data-integration platform we configure a single purchase-inbound sync strategy: the marketing cloud is the source, SQL Server is the target, isolated per distributor, pulled by time window, and written into a header table plus a line-item table.
Data Flow and Field Mapping
The end-to-end chain is marketing cloud (source) → Qeasy middleware → SQL Server (target). The source uses POST /erp/api/order/query/purInWarehsOrder to fetch documents; the target writes data through custom SQL into two tables: header gxkphz and line gxkpmx.
Key field mapping (condensed):
| Business meaning | Source (marketing cloud) | Target (header / line) |
|---|---|---|
| Document number | number | djbh (shared) |
| Unique key | id | id (used for idempotency) |
| Doc type | djlx | djbh–related djlx |
| Business date | rq | rq |
| Inbound time | ontime | ontime |
| Supplier / partner ID | wldwid | wldwid |
| Receiver / phone / addr | shouhr, lxdh, shhdz | shouhr, lxdh, shhdz |
| Tax-included amount | hsje | hsje |
| Remark | beizhu | beizhu |
| Original marketing-cloud doc number | webdjbh | webdjbh (header) |
| Product ID | spid | spid (line) |
| Warehouse ID / name | ckid, ckname | ckid, ckname (line) |
| Batch / expiry / shelf life | pihao, sxrq, baozhiqi | pihao, sxrq, baozhiqi (line) |
| Quantity / tax-included price | shl, hshj | shl, hshj (line) |
| Related doc number | xgdjbh | xgdjbh (line) |
The header and line tables are joined on djbh; line rows are identified by dj_sn. id is also the idempotency key — as long as the source id is stable, repeated pulls will not produce duplicate rows.
How to Configure on Qeasy
On the Qeasy platform this strategy is split into two actions: the source action queries approved inbound orders by distributor and time window; the target action writes the result into SQL Server.
Source configuration highlights:
- API:
/erp/api/order/query/purInWarehsOrder, POST. tenantIdhard-coded to a single distributor (a multi-distributor scenario must be split into separate strategies).status=1(approved / outbound) — never let unapproved drafts flow into the accounting DB.beginTimeuses the{{LAST_SYNC_TIME|datetime}}variable;endTimeis computed at runtime.- Both
numberandidhaveidCheckenabled, withidas the primary idempotency key andnumberas a business reference.
Target configuration highlights:
- Target DB: MSSQL; action type: EXECUTE.
extend_params_1points toitemListso the line-item array is bound to the line table.- The header SQL
INSERT INTO gxkphz ...and the line SQLINSERT INTO gxkpmx ...use named parameters. - The
djbhon both tables comes from the same source document number, guaranteeing a clean 1-to-N join.
A common Qeasy customer pattern is to centralize all code translations in the platform's mapping table — IDs like wldwid, ckid, spid that come in as strings on the source side and must become internal numeric keys on the target side. Keeping the mapping in one place lets a single edit apply to every strategy that needs it.
Implementation Steps
We split the rollout into three schedule phases so that nothing runs at high frequency before it is proven.
Phase 1 — establish the incremental baseline. Run a one-off "first full reload": do not pass beginTime, filter by status, and write all approved historical inbound orders into SQL Server. When the reload completes, Qeasy records LAST_SYNC_TIME as the starting point for subsequent incrementals.
Phase 2 — bring up incremental scheduling. Source cron is */3 7-23 * * * (every 3 minutes during business hours); target cron is */2 7-23 * * * (every 2 minutes), slightly faster than the source so the downstream never lags. Stay at low volume for 1–2 days.
Phase 3 — steady-state operation. Verify that LAST_SYNC_TIME advances as expected, that there is no "source has it, target missing it" gap, and that the idCheck hit rate looks healthy. If anything is missing, trigger a manual backfill — preferably by passing an explicit yxyNumber whitelist rather than widening the time window.
Lessons Learned
-
Not pinning the status filter. We once saw unapproved drafts flowing into the ERP because
statuswas left open; the books were later reversed and stock was wiped twice. Pinstatus=1on the source side and let Qeasy filter there — do not rely on downstream SQL. -
Inserting line items in a per-row loop. An earlier design wrote one INSERT per line, and a moderately large order dragged the run into minutes. The target
extend_sql_1supports array-based batch binding; always batch, never loop. This is a classic "correct but slow" pitfall. -
idCheck on
numberonly.numberis editable on the marketing cloud; onlyidis the true primary key. If onlynumberis checked, a source-side renumber will be treated as a new document and inserted again. Keepidas the idempotency key,numberas a business field. -
Scattered code mapping. We once had a
wldwidmapping hard-coded in three different strategies. When the source renamed its code, all three had to change — and one was missed. Centralized mapping tables are the standard Qeasy pattern: one edit, every strategy updated. -
Header and body released together. The source returns a header plus a nested line array. A common mistake is filling
main_paramscorrectly but forgetting to pointextend_params_1atitemList; the header inserts fine, the line table stays empty, and finance sees the right totals with no rows. The safe pattern is phased go-live: ship header-only first, verifydjbh/wldwid/hsje, then enable the body.
When to Use and When Not To
Use it when: there is a single distributor; inbound order volume is moderate (hundreds to a few thousand per day); the source supports time-windowed incremental queries; the target is SQL Server with custom tables; header and body must land in separate tables. Do not use it when: you need cross-distributor tenant isolation inside one strategy; the source only provides file exports with no API; the target is a SaaS that does not allow custom table structures.