Distribution Sales Return Sync in Practice: Encoding Lookup and Org Attribution from WMS to Kingdee Cloud
What This Strategy Solves
In distribution scenarios, the return party is no longer the end buyer but the distributor itself. Each distributor sits under a different sales organization and maps to different customer master data, so the ERP document attribution depends entirely on resolving the distributor code. The core value of this strategy is to unify, in one pass, document header-to-organization, header-to-customer, and line-to-material mapping for distribution sales returns.
Data Flow and Field Mapping
Data flows from the e-commerce WMS (return-inbound order) → the middle layer (Qeasy integration platform handling encoding lookups and mapping) → the ERP (distribution sales return KD_DSSAL_RTNSTOCK).
Key field mapping:
| Target Field | Mapping Type | Conversion Rule | Business Meaning |
|---|---|---|---|
| FBillTypeID | CONSTANT | DSXSTHD07 | Distribution sales return type |
| FBillNo | DIRECT | {{order_no}} | Inbound order number as document number |
| FDate | DIRECT | {{modified}} | Last modified time as document date |
| FSaleOrgId | COLLECTION | Lookup by fenxiao_nick_no against distributor mapping table, return FUseOrgID | Sales organization |
| FRetcustId | COLLECTION | Same lookup, return FCustID | Return customer |
| FStockOrgId | CONSTANT | 106 | Inventory organization |
| FSettleCurrId | CONSTANT | PRE001 | Settlement currency: CNY |
| FHeadNote | DIRECT | {{shop_remark}} | Remarks |
| Freamount | DIRECT | {{actual_refund_amount}} | Return amount |
| FThirdBillNo | DIRECT | {{refund_no}} | Original return order number |
| FEntity | COLLECTION | value=details_list | Line entries, generated row by row |
Line-level (inferred mapping, to be confirmed against actual API response): spec_no → material code, num → actual return qty, price → tax-inclusive price, amount → total amount, warehouse_no → warehouse code, remark → line note.
How to Configure on Qeasy
On the Qeasy data integration platform, this strategy runs as a "source QUERY + target EXECUTE" combination — no scripts required.
- Source metadata: Select the interface
wdt.wms.stockin.refund.querywithdetail. Put the pagination parameterpagerand business parameterparamsinto the request body. Useorder_noas the primary key, with idCheck enabled to prevent duplicate fetches. - Target metadata: Select Kingdee Cloud
batchSave, set FormId toKD_DSSAL_RTNSTOCK, Operation=Save,IsAutoSubmitAndAudit=true,IsVerifyBaseDataField=false,SubSystemId=21. - Centralized encoding mapping: Both distributor→customer and distributor→organization lookups point to the same "distributor-customer correspondence" table (hashed strategy ID), using
_findCollectionsyntax with theFWDTDCNumbercondition, returningFCustIDandFUseOrgID. This "centralized encoding mapping" pattern is very common among Qeasy customers — when a distributor is added or an organization changes later, only that one table needs editing, not every strategy. - Header and body staged mapping: The document header uses
_findCollectionto resolve the distributor code and fill in the organization and customer. The document body usesFEntityto referencedetails_listas a whole; the platform expands it row by row without hardcoding each field in the strategy. - Scheduling: Source runs
*/15 * * * *, target runs*/20 * * * *— source faster than target to avoid backpressure downstream.
Implementation Steps
Recommended phased scheduling:
- Incremental starting point: Use source
modified(last modified time) as the incremental cursor. Before the first sync, run a baseline of "data after today's 00:00" to avoid a flood of historical baggage. - Full trigger: Run only on first go-live or after the mapping table is rebuilt. Page backward by
created_timein descending order, stop when done, and immediately switch back to incremental. - Schedule frequency: Source every 15 minutes, target every 20 minutes. Distribution channel document volume is usually moderate — no need to push to 5-minute intervals. Leave Kingdee time for auditing and inventory write-back.
- Failure retry and alerting: Qeasy retries failed requests by default, but unmatched distributor code lookups should trigger separate alerts — they are the root cause of attribution chaos.
Lessons Learned
- Distributor code field-name confusion: Source metadata says
fenxiao_nick(nickname), but the lookup needsfenxiao_nick_no(code). If the upstream API only returns nicknames, the lookup returns empty, and both organization and customer go wrong. The safe practice is to capture the real response with Postman before going live and confirm whetherfenxiao_nick_noexists; if not, add a mapping script in the source extension. shop_remarkandremarkare not the same field: The target template uses{{remark}}, but the source main table actually hasshop_remark. A typical mistake is copying the template name directly, leaving FHeadNote empty forever. Grep for same-named fields in source metadata before configuring.- Logistics number and company are "ghost fields": The template references
logistics_noandlogistics_name, but the source main table only haslogistics_type. Either confirm they come from line items or extension fields, or simply leave them blank until the business side confirms — don't fabricate values just to fill fields. - Don't hardcode line-level fields: Set FEntity's value to
details_listas a whole reference; the row-levelspec_no → materialcorrespondence relies on material master data existing in Kingdee. Make sure SKU master data is fully set up on the Kingdee side before integration, otherwise the entire document will fail at save. IsVerifyBaseDataField=falseis a double-edged sword: Disabling base data validation lets the save go through, but errors in organization, customer, or material codes won't be reported. We recommend actively throwing an error when the lookup fails, rather than silently passing it — this is exactly why the "incremental and full dual-track" pattern needs periodic reconciliation.
Applicable and Non-Applicable Scenarios
Applicable: Distribution channels where the distributor is the return party, with multi-organization, multi-customer retail or FMCG enterprises; document volume in the low thousands per day with stable return frequency. Not applicable: ToB/ToC direct sales returns (use the corresponding sales return strategy); organizations where distributor codes are not yet mapped in the ERP master data; or large chains that need complex split-by-store or split-by-platform handling.