Jobs: scheduling and lifecycle
Change a job's customer or asset
/a/Job_setCustomer
Replace the job target and refresh historic customer details and one linked invoice.
When to use this endpoint
Use the customer/asset picker on an existing job. This can change billing context; it is not just an address override.
Authentication and permissions
Authenticate with signed API-key fields or a logged-in CRM session. Legacy edit-restriction bit 128 is enforced; client administrators retain the existing admin exception.
Targets must be active tenant customers/assets. If the change would affect a primary linked invoice, the legacy finance restriction (crm_access bit 64) is checked before any write.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
id | Integer string | Yes | Positive active job ID. |
customer_id | Integer string | Yes | Positive existing non-deleted customer/asset ID for the chosen type. |
customer_type | Integer string | No | 0 customer (default), 1 asset; other values rejected. |
Example request
$result = FM_api('Job_setCustomer', [
'id' => '1042', 'customer_id' => '1088', 'customer_type' => '0',
]);
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":"missing or invalid parameter: customer_id"} | Missing/zero target ID. |
{"error":"job does not exist"} | Missing/deleted job. |
{"error":"Invalid Customer Type."} | Type is not 0/1. |
{"error":"No permission to edit"} | Bit 128 set. |
{"error":"cannot link to remote asset because the Code is missing from the local asset"} | Remote asset preparation failed after the local update. |
{"error":"Invalid job customer or asset"} | Nonpositive, missing or deleted target. |
{"error":"This user does not have access to certain CRM features. Check user permissions."} | Finance-restricted caller would change a linked invoice; no primary write. |
{"error":"Unable to save job customer"} | Primary persistence failed. |
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 historic customer/asset address details at the job start and saves customer_details and parent-customer caches. A fully populated unchanged target returns value already set before writing; a stale snapshot is refreshed.
- Validates a changed/refreshed target and finance access before the primary write; false/exception persistence returns Unable to save job customer before history or downstream changes.
- Updates one active primary linked invoice, with the legacy fallback: replaces customer/type, clears target_type/target_id overrides, refreshes the snapshot and fires Invoice_edit. This is not an all-linked-invoices synchronization.
- Outsourced customer targets use remote customer_id=-1 plus source/snapshot metadata; asset targets resolve/create the remote asset. Local, remote and invoice follow-ups are not a distributed transaction.
Side effects
- Writes job target/snapshot/parent caches and edit metadata; logs set customer; may create/update remote asset context and modify one linked invoice. Does not explicitly recount old/new customer job totals.
See it in Fieldmotion
CRM1
On the Job detail page, change the customer/asset selector. pageJob.js sends customer_id and customer_type to this route.
CRM2
No direct caller was found. CRM2 customer editing uses mapped Job_updateData rather than this narrow legacy route.
Related endpoints
Job_setMeetingTimeruns dependent scheduling updates.Job_copycreates fresh copies and returns their complete ID list.Job_setStatusincludes the extra single-job transition follow-ups.