Purchase orders
Convert a requisition into supplier orders
/a/PurchaseOrder_createFromRequisitionOrder
Copy selected supplier lines from a Requisition Order into new Purchase Orders and reassign its order containers.
When to use this endpoint
Use the Requisition Order conversion action after choosing suppliers and matching forms. Read back all created orders before repeating a failed request.
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 Add on either page. Non-administrators with legacy Purchase Orders visibility disabled (crm_access bit 256) are denied.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
ro_id | Integer-compatible | Yes | Positive local Requisition Order ID. The source must be active, visible, Approved and not already converted. |
suppliers | Native array or JSON array string | Yes | Nonempty selected supplier IDs covering every source line, without duplicates; order determines which new order carries the source carriage. |
form_ids | Native array or JSON array string | Yes | Native or JSON array of active type-5 form IDs (or 0), aligned one-for-one with the supplier list. |
reference | Text | No | Trimmed, default empty; maximum 32 bytes. Copied to every new order. |
Example request
$result = FM_api('PurchaseOrder_createFromRequisitionOrder', [
'ro_id'=>'312',
'suppliers'=>json_encode(['42']),
'form_ids'=>json_encode(['5']),
'reference'=>'Approved requisition',
]);
Example response
{
"ok": 1,
"po_ids": [
1042
],
"poDetails": [
{
"id": 1042,
"stockID": 71
}
]
}
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": "missing or invalid parameter: ro_id"} | Missing/nonpositive source ID. |
{"error": "missing or invalid parameter: suppliers"} | The supplier selection is absent. |
{"error": "missing or invalid parameter: form_ids"} | The matching form list is absent. |
Legacy application errors may be returned with HTTP 200. Check the decoded response for error, not only the HTTP status.
Behaviour and edge cases
- Requires Requisition Order View/Edit as well as Purchase Order View/Add. The source must be active, visible and Approved (status 1). Existing linked orders or copied line links block another conversion; processed sources are read-only.
- Select a nonempty supplier list covering every source line, with one aligned form per supplier. Selected suppliers must each have lines; duplicates/mismatched lists are rejected. Supplier/form/target references use checked header creation.
- Copies each supplier’s lines in source-ID order with new line IDs/sort numbers and writes the source poe_id links. poDetails has one item per copied line: id is the new header ID and stockID is the source stock ID.
- Carriage is charged once: the first selected supplier order receives the source delivery net/tax; later orders receive zero carriage. Across the new orders, saved line totals plus carriage are preserved. Confirm the selected order before conversion if a particular supplier must carry delivery.
- Container moves require an unambiguous line/supplier identity. A stock identity shared across suppliers is rejected instead of guessing a quantity split. Matching containers retain their destination; initial Requisition availability becomes initial Purchase availability for its new order.
- Copies valid source delivery date/contact/instructions/address and the target, including Warehouse type 7 with ID 0. Marks the source Processed (2), stores all new po_ids and records its status Workflow when enabled.
- All copies, allocation moves, source links/status, Workflow records and history share one transaction. An invalid conversion creates no partial orders; notifications run after commit.
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.
- Writes new headers/lines, source line links, order-container ownership, source status/po_ids and checked history. Queues the source update notification.
See it in Fieldmotion
CRM1
In CRM1 Requisition Order details, use Create Purchase Order and inspect PurchaseOrder_createFromRequisitionOrder with supplier/form arrays.
CRM2
In CRM2 Requisition Order details, choose supplier forms and create the orders; inspect the same route. The client then performs a separate update of the first order’s metaLink.
Related endpoints
PurchaseOrder_get— Inspect each created header.PurchaseOrderEntry_getRequestedDetails— Read back copied lines by poID.