Aiden WMS

Sales Return

TL;DR — Aiden WMS Sales Return Inbound Mapper
  • Purpose: Turn a completed WMS sales return into a SAP B1 Return or Credit Note, enriched with B1 Return Request line data for correct base-linking, BOM, and tracking.

  • Endpoint decision (runtime):

    • If first document’s first line BaseType = 13 (A/R Invoice) → POST CreditNotes.

    • Otherwise → POST Returns.

  • Inputs & enrichment:

    • From WMS: transaction.id, processDate, businessPartner, documents[].customFields.externalId (base doc entry), customFields.DocEntry (Return Request DocEntry), header/line expenses, lines (with salesBom), savedLines (quantity, serial, batch, expiry, baseQuantity).

    • Enrichment: GET B1 ReturnRequest by DocEntry (DocEntry, DocNum, DocumentLines) for base-line matching and BOM joins.

  • Header mapping (each output document):

    • CardCode ← businessPartner.businessPartnerId.

    • DocDate ← processDate.

    • U_AEN_WMS_TRANSID ← transaction.id.

    • Comments not mapped.

  • How lines are built (parallel expansions):

    • Serial path: savedLines with serialNumber → SerialNumbers[]; line Quantity = sum of saved serial quantities per base line.

    • Batch path: savedLines with batchNumber → BatchNumbers[] (BatchNumber, ExpiryDate, Quantity); line Quantity = sum over batches.

    • Non batch/serial path: remaining saved quantities without tracking blocks.

    • Sales BOM path: when salesBom present and Return Request lines found, component quantities derived via singleQuantity with min/divide logic; base type typically 234000031 (Return Request).

    • Base links:

      • BaseEntry ← documents.customFields.externalId (or matched Return Request DocEntry).

      • BaseLine ← matched lineNum/group or VisualOrder+1 (path-dependent).

      • BaseType ← valuemap from objectType on some paths (Orders→17, StockTransferRequests→1250000001); many other paths force 234000031.

  • Expenses:

    • Header: documents.customFields.DocumentAdditionalExpenses → B1 DocumentAdditionalExpenses[] (ExpenseCode, LineTotal, GroupCode, DistributionMethod, VatGroup, BaseDocEntry, BaseDocLine, BaseDocType=234000031).

    • Lines: lines.customFields.DocumentAdditionalExpenses → DocumentLineAdditionalExpenses[] (ExpenseCode, LineTotal, GroupCode, DistributionMethod, VatGroup). BaseGroup only mapped on the non-batch/serial path; no BaseDoc* on line expenses.

  • Traceability:

    • U_AEN_WMS_TRANSID = transaction.id on header.

    • BaseEntry/BaseLine/BaseType set per line for ERP link-back.

  • Key expectations & caveats:

    • Return Requests must exist in B1; WMS must provide correct DocEntry for enrichment.

    • Endpoint (Returns vs CreditNotes) is chosen only from the first document’s first line BaseType.

    • Packages/SSCC are not generated by this mapper.

    • Warehouse/bin are not primary line attributes here; base-linked quantities dominate.

  • Consultant checklist:

    • Ensure WMS provides customFields.DocEntry (Return Request) and externalId, plus accurate line numbers.

    • Set lines[].customFields.BaseType = 13 when credit notes are required; otherwise returns are posted.

    • Populate savedLines with complete serial/batch/expiry where applicable.

    • Keep salesBom flags and Return Request VisualOrder consistent for correct BOM components.

    • Use transaction.id/U_AEN_WMS_TRANSID and base refs for reconciliation.

Functional documentation for the Aiden WMS sales return inbound mapper.

This document describes what happens after the mapper is installed: how a WMS sales return completion is enriched with SAP Business One (B1) return request data, which B1 document is posted (Returns or Credit Notes), and which field rules apply. It is intended for end-users and functional consultants.


1. Overview



Source

Aiden WMS sales return / inbound return completion (Kafka)

Enrichment

SAP B1 Return Request (ReturnRequest GET)

Target

SAP B1 Returns or Credit Notes (POST via Service Layer / Kafka)

Purpose

Confirm warehouse return receipt against open return request(s) in B1

After installation, when WMS finishes receiving a sales return, the integration:

  1. Reads return request DocEntry values from the WMS message

  2. Loads matching B1 return request line data

  3. Maps WMS picked/saved quantities (serials, batches, plain lines, sales BOM) into B1 document lines

  4. Posts either a Return or a Credit Note, depending on base type

Document type selection (runtime)

Condition

B1 endpoint

HTTP method

First line documents[0].lines[0].customFields.BaseType equals 13

CreditNotes

POST

Any other / missing BaseType

Returns

POST

Base type 13 is the B1 object type for A/R Invoice. When the return is based on an invoice, WMS/B1 expect a credit note; otherwise a return document is posted against the return request (object type 234000031 in many line paths).


2. What the mapper uses as input

2.1 WMS message

Typical structure:

  • transaction.id — WMS transaction id (external application id + U_AEN_WMS_TRANSID)

  • transaction.type / dates — present on payload; type not used for endpoint routing in Java

  • documents[]:

    • businessPartner.businessPartnerId → B1 CardCode

    • processDate → B1 DocDate

    • customFields.externalId — B1 base document entry used on lines (BaseEntry)

    • customFields.objectType — used in BaseType valuemap for some line paths

    • customFields.DocEntryReturn Request DocEntry(s) used for B1 GET filter

    • customFields.DocumentAdditionalExpenses[] — header expenses (map to B1 header DocumentAdditionalExpenses)

    • lines[] — planned/document lines (lineNum, salesBom, quantity, …)

    • lines[].customFields.DocumentAdditionalExpenses[]line expenses (WMS name); on B1 output these become DocumentLines[].DocumentLineAdditionalExpenses[]

    • savedLines[]actual received units (quantity, batch, serial, license, carrier, baseQuantity)

2.2 B1 Return Request enrichment (automatic)

Before mapping, the integration:

  1. Splits documents[] and collects each customFields.DocEntry

  2. Builds an OData filter: DocEntry eq <id> (or multiple or clauses for unique entries)

  3. GET ReturnRequest?$select=DocEntry,DocNum,DocumentLines&$filter=…

  4. Stores the response as the second MapForce input

Business impact: return request documents must already exist in B1, and WMS must carry the correct customFields.DocEntry. Wrong/missing DocEntry yields empty enrichment and incomplete base-line matching (especially for BOM).

2.3 Correlation / monitoring

Value

Source

Use

Integration message id

Kafka key

XIAM correlation

External application id

transaction.id

XIAM

B1 U_AEN_WMS_TRANSID

transaction.id

Trace WMS tx on B1 document


3. Business behavior

3.1 Header of each B1 document

For each WMS documents[] entry, the mapper produces a B1 document object with:

B1 field

Source

Rule

CardCode

businessPartner.businessPartnerId

Direct

DocDate

processDate

Direct

U_AEN_WMS_TRANSID

transaction.id

Direct

Comments

Not mapped

3.2 How lines are built

WMS savedLines drive quantities and tracking (serial/batch). They are matched to document lines (via documentLine / lineNum) and, for sales BOM, to Return Request lines (DocEntry, LineNum, VisualOrder).

MapForce emits several parallel DocumentLines expansions (clones), similar to other inbound goods mappers:

Expansion (logical)

When

Quantity

Tracking

Serial

savedLines.serialNumber not empty

Sum of saved qty per base line

SerialNumbers[]

Batch

Batch present on saved line

Sum of saved qty per base line

BatchNumbers[] (number, expiry, qty)

Non batch/serial

Residual path (no serial/batch tracking on that path)

Aggregated qty

No batch/serial blocks

BOM articles

Sales BOM structure + Return Request join

Derived from WMS qty and BOM singleQuantity (min/divide logic)

Expenses can still attach

Base document references on lines (typical):

B1 line field

Typical source

BaseEntry

WMS documents.customFields.externalId (or matched return request DocEntry in joins)

BaseLine

Matched document/return-request line number (group key / lineNum / VisualOrder+1 depending on path)

BaseType

Valuemap from objectType, or constant 234000031 (Return Request) on non-serial/BOM-style paths

3.3 BaseType valuemap (customFields.objectType)

Used on the serial (and related) path:

WMS objectType

B1 BaseType

Orders

17

StockTransferRequests

1250000001

Other

Passthrough / default input mode

Many non-serial / BOM / expense base-type fields are forced to constant 234000031 (B1 Return Request object type), so returns against return requests keep a stable base type even when objectType valuemap does not apply.

3.4 Serial lines

  • Filter: serial number not equal to empty

  • Group-by document line; sum quantities

  • B1 SerialNumbers[].InternalSerialNumber ← WMS serial

  • B1 SerialNumbers[].Quantity ← saved quantity (per serial row path)

  • Line Quantity ← aggregated sum for that base line

3.5 Batch lines

  • Filter: batch number present (empty batch excluded from this path)

  • Group-by document line; sum quantities

  • B1 BatchNumbers[]: BatchNumber, ExpiryDate, Quantity from saved lines

  • Line Quantity ← aggregated sum

3.6 Non batch/serial lines

  • Intermediate JSON path labeled for non-batch/serial units

  • BaseType often 234000031

  • Quantity from aggregated saved quantities without serial/batch sub-structures

3.7 Sales BOM lines

When WMS lines carry salesBom (parent, parentLine, singleQuantity, respectSingleQuantity):

  • Mapping joins B1 Return Request lines where:

    • Return request DocEntry matches WMS external/base document context

    • Return request visual order context matches (VisualOrder + 1 compared to parent line, etc.)

  • Component quantities use singleQuantity and min/divide against WMS line quantities so BOM components stay consistent with kit structure

  • Output lines use Return Request base type 234000031 on the BOM expansion

Consultant impact: Visual order and sales BOM flags on the original return request / WMS message must stay consistent. Broken parent/child links produce wrong component quantities or missing BOM lines.

3.8 Additional expenses

Header and line expenses use different B1 structures.

Header expenses from documents.customFields.DocumentAdditionalExpenses:

  • Copied to B1 document-level DocumentAdditionalExpenses[]

  • BaseDocEntry ← WMS externalId

  • BaseDocLine ← expense LineNum

  • BaseDocType ← constant 234000031 (typical)

  • ExpenseCode, LineTotal, GroupCode, DistributionMethod, VatGroup copied

Line expenses from lines.customFields.DocumentAdditionalExpenses:

  • Attached on matching DocumentLines expansions (serial / batch / non-batch-serial / BOM) as B1 DocumentLineAdditionalExpenses[] (not the header-shaped expense block)

  • Mapped fields: ExpenseCode, LineTotal, GroupCode, DistributionMethod, VatGroup

  • No BaseDocEntry / BaseDocLine / BaseDocType on line expenses (removed in the line-expense mapping)

  • LineNumber exists on the output schema but is not mapped

  • BaseGroup is only wired on the non-batch/serial path (from WMS GroupCode); serial, batch, and BOM line-expense paths do not map BaseGroup

3.9 Packages

DocumentPackages exists on the output schema. In the current MapForce definition, package fields are largely not wired (no reliable license/carrier package generation like the goods-delivery mapper). Do not expect SSCC packages from this mapper unless the MFD is extended.


4. Field mapping tables

Columns: B1 target field | WMS / ReturnRequest source | What happens | Notes

4.1 Header

B1 target field

WMS / source input

What happens

Notes

CardCode

documents.businessPartner.businessPartnerId

Direct

Customer

DocDate

documents.processDate

Direct


U_AEN_WMS_TRANSID

transaction.id

Direct

Traceability

Comments

Not mapped


Document endpoint

lines[0].customFields.BaseType

13→CreditNotes else Returns

Java routing, not MFD

4.2 Document lines (common)

B1 target field

WMS / source input

What happens

Notes

DocumentLines[].BaseEntry

customFields.externalId / RR DocEntry

Direct / join

Base document

DocumentLines[].BaseLine

lineNum / group key / VisualOrder+1

Match + transform

Path-dependent

DocumentLines[].BaseType

objectType valuemap or 234000031

Valuemap or constant

See §3.3

DocumentLines[].Quantity

savedLines.quantity (+ BOM rules)

Sum / min / divide

Path-dependent

4.3 Serials (conditional)

B1 target field

WMS / source input

What happens

Notes

Serial path used?

savedLines.serialNumber non-empty

Filter

Empty serial → other path

SerialNumbers[].InternalSerialNumber

serialNumber

Direct


SerialNumbers[].Quantity

saved line qty

Direct / aggregate


Line Quantity

saved qtys

Sum per base line


4.4 Batches (conditional)

B1 target field

WMS / source input

What happens

Notes

Batch path used?

savedLines.batchNumber present

Filter


BatchNumbers[].BatchNumber

batchNumber

Direct


BatchNumbers[].ExpiryDate

expiryDate

Direct


BatchNumbers[].Quantity

saved qty

Direct / aggregate


Line Quantity

saved qtys

Sum per base line


4.5 Sales BOM (conditional)

B1 target field

WMS / ReturnRequest source

What happens

Notes

BOM path used?

lines.salesBom + RR lines

Join on DocEntry / visual order

Needs GET ReturnRequest

Component Quantity

WMS qty + singleQuantity

min / divide logic

Kit consistency

BaseType

Often 234000031

Return request

4.6 Header additional expenses

Document-level B1 DocumentAdditionalExpenses[] (distinct from line-level DocumentLineAdditionalExpenses).

B1 target field

WMS / source input

What happens

Notes

ExpenseCode

Header expense ExpenseCode

Direct


LineTotal

LineTotal

Direct


GroupCode

GroupCode

Direct


DistributionMethod

DistributionMethod

Direct


VatGroup

VatGroup

Direct


BaseDocEntry

customFields.externalId

Direct


BaseDocLine

expense LineNum

Direct


BaseDocType

Constant 234000031 (typical)


4.7 Line additional expenses

B1 target collection: DocumentLines[].DocumentLineAdditionalExpenses[].
WMS source collection: lines.customFields.DocumentAdditionalExpenses[] (name differs from B1 output).

B1 target field

WMS / ReturnRequest source

What happens

Notes

DocumentLines[].DocumentLineAdditionalExpenses[]

lines.customFields.DocumentAdditionalExpenses[]

Attached on serial / batch / non-batch-serial / BOM expansions

Output name ≠ WMS input name

ExpenseCode

Line expense ExpenseCode

Direct


LineTotal

LineTotal

Direct


GroupCode

GroupCode

Direct


DistributionMethod

DistributionMethod

Direct


VatGroup

VatGroup

Direct


LineNumber

Not mapped

Present on schema only

BaseGroup

WMS GroupCode

Copied only on non-batch/serial path

Unwired on serial / batch / BOM

BaseDocEntry / BaseDocLine / BaseDocType

Not used on line expenses

Header expenses still use BaseDoc* (see §4.6)


5. Value translations (reference)

5.1 Endpoint routing

documents[0].lines[0].customFields.BaseType

B1 POST endpoint

13

CreditNotes

Other / empty

Returns

5.2 Object type → BaseType (valuemap)

WMS customFields.objectType

B1 BaseType

Orders

17

StockTransferRequests

1250000001

Unlisted

Default/input mode (passthrough)

5.3 Return request object type constant

Constant

Meaning in this mapper

234000031

B1 Return Request object type — used as BaseType / BaseDocType on many return-request-based lines and expenses

5.4 B1 GET

Setting

Value

Endpoint

ReturnRequest

Select

DocEntry,DocNum,DocumentLines

Filter

DocEntry eq … from WMS customFields.DocEntry (unique, OR-combined)


6. What is not mapped / important omissions

Topic

Behavior

Comments

Not mapped

Document packages / SSCC

Schema present; not effectively mapped in current MFD

Warehouse / bin on B1 return lines

Not a primary mapped line attribute in this MFD (base-linked quantities dominate)

Line expense LineNumber

On DocumentLineAdditionalExpenses schema; not mapped

Line expense BaseGroup

Only on non-batch/serial expansion (from GroupCode); not on serial / batch / BOM

Line expense BaseDoc*

Not mapped on line expenses (unlike header DocumentAdditionalExpenses)

Scenario samples

scenario_files/1_mainRoute is dummy — not expected I/O

Endpoint choice

Driven only by first document’s first line BaseType — multi-document mixed types are not re-evaluated per document in Java

Credit note vs return content

Same MapForce mapping; only the Service Layer endpoint changes


7. End-to-end expectation (happy path)

  1. WMS completes a sales return receipt and publishes a message with savedLines and return request DocEntry.

  2. Integration GETs B1 Return Request line data.

  3. Mapper builds B1 document(s): customer, date, WMS transaction id, lines with base refs, serials/batches/BOM as applicable, expenses.

  4. If first line BaseType is 13 → POST CreditNotes; else POST Returns.

  5. Support uses U_AEN_WMS_TRANSID / transaction.id and base document refs for reconciliation.


8. Example (illustrative shape)

Scenarios in-repo are placeholders. Expected shape from MFD + runtime:

WMS input (conceptual)

Field

Example

transaction.id

SR-2025-001

BP

C20000

processDate

2025-10-15T…

customFields.DocEntry

Return request 950

customFields.externalId

Base doc entry as used for BaseEntry

lines[0].customFields.BaseType

empty/234000031 → Returns; or 13 → CreditNotes

savedLines

Qty + optional serial/batch

B1 output (conceptual)

Field

Example

Endpoint

Returns or CreditNotes

CardCode

C20000

DocDate

process date

U_AEN_WMS_TRANSID

SR-2025-001

Lines

BaseEntry/BaseLine/BaseType + Quantity; serial and/or batch children as received

Header expenses

DocumentAdditionalExpenses when sent on document customFields

Line expenses

DocumentLines[].DocumentLineAdditionalExpenses when sent on lines.customFields.DocumentAdditionalExpenses


9. Implementation checklist for consultants

  1. Return requests exist in B1 before WMS confirmation.

  2. WMS sends correct customFields.DocEntry (return request) and externalId / line numbers for base linking.

  3. Set lines[].customFields.BaseType = 13 when the business case must post a Credit Note; otherwise expect Returns.

  4. For serial/batch items, populate savedLines serial/batch/expiry completely.

  5. For sales BOM, keep salesBom and return-request VisualOrder consistent.

  6. Use transaction.id / U_AEN_WMS_TRANSID for support.

  7. Do not expect package/SSCC generation from this mapper today.

  8. Validate header expenses (DocumentAdditionalExpenses) and line expenses (DocumentLineAdditionalExpenses from WMS line DocumentAdditionalExpenses) if freight must copy to the B1 return/credit note.


10. Source artifacts (for reference)

Artifact

Role

mappings/sales-return-inbound.mfd

MapForce mapping (field logic)

mappings/input_wms_delivery_notes.schema.json

WMS input contract

mappings/input_sales_order.schema.json

ReturnRequest enrichment schema (naming historical)

mappings/output_sap_delivery_notes.schema.json

B1 Returns/CreditNotes-shaped output

src/.../route/MainRoutes.java

Kafka, BaseType routing, mapper

src/.../route/SAPB1Routes.java

GET ReturnRequest

src/.../aggregator/ReturnDocEntryAggregator.java

DocEntry filter aggregation

src/.../mapper/Mapper.java

MapForce (WMS + return body)

scenario_files/1_mainRoute/

Placeholder samples


Generated from the mapping definition and integration behavior in this project. If the MapForce mapping or routing changes, this document should be reviewed and updated.


Maintaining this document

For the original documentation intent, when to update, source-of-truth checklist, and a ready-made refresh prompt, see README.md and the repository AGENTS.md.