Purchase orders
Remove mapped lines matching filters
/a/PurchaseOrderEntry_deleteData
Delete line rows selected by mapped equality filters, including a layout’s complete old line set.
When to use this endpoint
Use the layout replacement primitive with explicit line IDs or one active visible parent. Parent-only deletion receives the same total/approval/allocation protection as explicit-line removal.
Authentication and permissions
Authenticate with signed API-key fields or a logged-in CRM session. Session requests use dispatcher CSRF protection when configured. API keys use their owner’s permissions.
Requires explicit View on Purchase Order or Purchase Orders, plus Edit on either page. Non-administrators with legacy Purchase Orders visibility disabled (crm_access bit 256) are denied.
Explicit line IDs are checked against their active, visible parent orders. A supplied po_id must match the line’s owner. These are tenant-local record IDs, not displayed order numbers.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
id | Positive scalar, native or JSON list | IDs or parent | Explicit local line IDs. An empty list returns ok without deleting anything. Cannot be combined with arbitrary extra row filters. |
poID | Positive integer or digit string | IDs or parent | Positive parent selector; po_id/roID are supported aliases and must agree. Removes the complete bounded line set with parent totals/history/approval follow-ups. |
Other mapped stored fields | Scalar or native array | Unsupported | Extra row filters are rejected. Select explicit line IDs or one parent; broad text/quantity equality deletion is no longer accepted. |
ids | Native or JSON list | No | Supported ID-list alias. id takes precedence; the exact guarded ID set is deleted. |
Example request
$result = FM_api('PurchaseOrderEntry_deleteData', ['id'=>'2081']);
Example response
{
"ok": 1
}
Errors and unusual responses
| Response | Condition |
|---|---|
{"error":"not logged in"} | No authenticated tenant context is available. Invalid signed credentials can be rejected by the dispatcher before the handler runs. |
{"error": "permission denied"} | Page/action rights or the legacy visibility setting deny access. |
{"error": "purchase order does not exist"} | An explicit parent/header ID is absent, deleted or outside the caller’s scope. |
{"error":"Cannot change stock quantities or identity on an allocated or received Purchase Order"} | The change would invalidate existing allocations or receipts; the transaction rolls back. |
Legacy application errors may be returned with HTTP 200. Check the decoded response for error, not only the HTTP status.
Behaviour and edge cases
- Uses explicit positive scalar/native/JSON line IDs, or a canonical parent selector poID/po_id/roID. Empty ID lists return ok without broadening; missing selectors and extra mapped row filters are rejected.
- Every selected line/parent is checked for active visibility and Edit permission under the owner lock. Parent aliases must agree; an alias cannot authorize deletion from another header.
- Resolves the exact line set, deletes it and updates every parent’s totals/timestamp/history/approval within one transaction. A parent-only deletion of the final line retains carriage in header totals.
- Preserves compatible allocated destinations and rejects identity/quantity removal from allocated or received orders. Layout_setValue defers reconciliation until the complete replacement exists, allowing an equal replacement to retain allocations/approval.
- The existing physical row-removal/deletion-log lifecycle remains; no soft-delete schema change is included.
Side effects
- Writes use the tenant-owner lock and a transaction or caller savepoint. A rejected operation rolls back its local writes and checked history. Earlier separate API requests remain committed.
- Edit events, notifications and form follow-ups run after the owning commit. A saved/no-replay warning identifies committed data with a failed follow-up; inspect the saved state rather than repeating creation or sending.
- Deletes the bounded selected set, records shared deletion audit, reconciles availability and refreshes parent totals/history/approval. Full layout replacement shares the same owning transaction.
See it in Fieldmotion
CRM1
No direct CRM1 caller was found; the legacy editor uses PurchaseOrderEntry_delete.
CRM2
In CRM2 Purchase Order details, save the line spreadsheet and inspect Layout_setValue. The Purchase Order layout saves the complete spreadsheet atomically, updates matched lines in place to retain receipt references, creates new lines and removes only omitted lines.
Related endpoints
PurchaseOrderEntry_createData— Create replacement rows after deletion.PurchaseOrderEntry_delete— Remove an explicit legacy line with stronger follow-ups.