Postman collection
Replacements Write

pixiCreateReplacementOrder

Creates a replacement order for one or more return case lines, logs the request in the return case history and returns the new order number.

Creates a replacement (Ersatzauftrag) for returned items, based on the return case lines passed in ReturnLines.

Input format: ReturnLines is a list of RET_LINE_ID values separated by , or ; (e.g. 1024,1025). Semicolons are converted to commas, the string is trimmed and a trailing comma is added if missing.

Steps

  1. VAT check: For the first return line only, the shipping country of the related Rechnung (Invoices.ShipAdrRef → Addresses.Country) and the country flag ForceCountryVAT are determined. If no VAT rate valid today exists in VATs for that country:
    • with ForceCountryVAT = 1 an error is raised and nothing is changed;
    • otherwise Pixi_InsertDefaultVATRateForCountry is executed to derive a default VAT rate from the default country.
  2. History and status: For every return line a row is inserted into RET_CASES_HISTORY (ACTION_TYPE = 8, text from the translation key ReplacementRequestAPI in language Language_Id, with %ItemName% replaced by the Artikel name). The line status in RET_CASE_LINES is set to RPL (processing replacement). The editor is stored as Employee + ' (API)', or API if Employee is empty.
  3. Replacement order: Pixi_CreateReplacementForReturnLines is called with all lines. Within its own transaction it
    • collects the original order lines (only order lines with status AUS, only return lines with status RPL) with the returned quantity,
    • sets the return lines to status SHI (waiting for shipping),
    • creates addresses for the customer and shop and creates the replacement order via Pixi_CreateReplacementOrder,
    • writes the RET_LINE_ID into Orderlines.BackorderRef of the new order lines with the same Artikel, so that the return case can be closed at ship-out.
  4. The new order number is returned as a single row (NewOrderNr), in the output parameter NewOrderNr and as the procedure return value.

Notes

  • No overall transaction: the history rows and the status change to RPL are written before and outside the transaction of Pixi_CreateReplacementForReturnLines. If the replacement creation fails, these changes remain.
  • The VAT check uses only the first return line. Customer, shop and location of the new order are taken from the last processed line, so all lines should belong to the same customer/Rechnung.
  • If the first return line does not exist, the country cannot be determined and the call fails with an error from Pixi_InsertDefaultVATRateForCountry (unknown country code).
  • Return lines whose original order line is not in status AUS are skipped; if no line qualifies, the inner procedure raises Wrong Data. Errors from the inner procedure are logged via log.InsertError and re-raised via sp_Exception_ReRaise (not attached; exact message format unknown).
  • Pitfalls in list parsing: IDs are removed from the list by text replacement of ID,. Pass plain IDs without spaces or leading zeros. An empty ReturnLines value, or IDs that are suffixes of other IDs in the list (e.g. 12,112), can lead to parsing errors or an endless loop.
  • Lookups use NOLOCK.
  • The header comment of the procedure ("Checks pixi* user credentials") does not match its function.
  • The VAT error message contains the literal placeholders [Order/Invoice/...] and {shipping country}; they are not filled in.

Tables used

RET_CASE_LINES · Write RET_CASES_HISTORY · Write InvLines · Read Invoices · Read Addresses · Read Countries · Read VATs · Read Items · Read
SQL object:
dbo.pipiCreateReplacementOrder
Updated at 2026-10-30