Postman collection
Returns Write

pixiAddReturnCaseLine

Adds a line for an invoice line to an existing return case, or creates a new empty return case if no return case ID is passed.

The call behaves differently depending on RET_ID.

RET_ID is NULL or 0

  • pixiCreateReturnCase is executed with ReturnDate, ReceiversComment and Employee. It creates a new return case header in RET_CASES with status NEW and returns its RET_ID and RET_NUMBER.
  • No return line is added in this case. The new ID is not taken over internally. To add the line, the call has to be repeated with the returned RET_ID.

RET_ID is set (not 0)

A row is inserted into RET_CASE_LINES only if all of these conditions are met:

  • the invoice line InvLineKey exists and has ItemQty > 0;
  • ItemQty >= QuantityToReturn;
  • the linked order line has status AUS;
  • there is no credit note that refers to the same invoice (RefToInvoiceKey) and contains a line for the same order line.

The new line gets these values:

  • status AOK if ItemOk = 1, otherwise DAM;
  • the customer comment, receiver comment and return reason, with NULL stored as an empty string;
  • the quantity QuantityToReturn and the reference to the invoice line;
  • create date GETDATE() and create employee <Employee> (API), or API if no employee is given.

Afterwards the call always returns one row with the return case ID and the ID of the new line. If no line was inserted because a condition was not met, RET_LINE_ID is NULL.

Notes

  • Pitfall: without RET_ID only an empty return case is created. InvLineKey, QuantityToReturn, ItemOk, ReturnReason and CustomersComment are ignored in that case. Use the returned RET_ID in a second call.
  • The call raises no error if a condition fails. Check RET_LINE_ID for NULL to detect that no line was inserted.
  • The code does not check whether the invoice line is already part of another return line. Repeated calls can create several return lines for the same invoice line, as long as each quantity is not larger than ItemQty.
  • The code does not check whether the given RET_ID exists, and it does not reject negative quantities.
  • ReturnDate is only used when a new return case is created.
  • ReceiversComment is stored on the return case header when one is created, and on the line when a line is added.
  • If ItemOk is NULL, the line gets status DAM.
  • The invoice and order lines are read with NOLOCK.
  • No explicit transaction is used.

Tables used

RET_CASE_LINES · Write RET_CASES · Write Invlines · Read Orderlines · Read Invoices · Read
SQL object:
dbo.pipiAddReturnCaseLine
Updated at 2026-10-30