Programme Contracts
Save module Form defaults
/a/ContractProgramme_saveDefaults
Maintain inherited Service and QI Forms for Programme Contracts.
When to use this endpoint
Read bootstrap.form_defaults immediately before saving. Send its revision and changed choices. Existing zero/blank Contract choices inherit at read/publication time; this does not rewrite individual overrides.
Send operation fields inside one JSON-encoded data object. When data is present it replaces top-level operation fields; otherwise the handler accepts the top-level request. String data is limited to 2 MB. Reserved transport/internal keys are removed. Malformed or non-array JSON becomes an empty input, so validate JSON before sending.
Authentication and permissions
Authenticate with a signed API key or logged-in CRM session; session requests follow dispatcher CSRF checks. API-key requests use the key owner’s identity and permissions.
Requires the Contracts entitlement (features & 64), features2.contractProgrammes and Contracts View. Requires Contracts Edit.
All storage belongs to the authenticated tenant. Contract operations follow the actor’s recursive HR manager/team scope, or the configured TeamAccess Contract/Department policy. Client administrators have broad Contract scope; private Programme and route ownership still applies. Active assignees must be within the permitted team.
Only a client administrator may perform this operation, in addition to the permissions above.
The tenant must have the Programme storage upgrade (foundation 803; independent route ownership 804 before planning). Requests never create or repair tables. A missing/incompatible storage failure can return an initialization/storage error or Contracts operation failed. Check the saved state before retrying.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
revision | Integer-compatible | Yes | Exact current revision; initial configuration uses 0. |
service_form_id, qi_form_id | Positive ID or 0 | No | Unarchived Job Form IDs; zero clears. Omitted values are preserved. |
qi_field_id | String | No | Existing select/selectbox/radio/contract-grade field ID on QI Form, at most 64 characters; blank clears. QI changes require contractProgrammeQI. |
Example request
$result = FM_api('ContractProgramme_saveDefaults', [
'data' => json_encode([
'revision' => 0,
'service_form_id' => 301,
'qi_form_id' => 302,
'qi_field_id' => 'grade',
]),
]);
Example response
{
"ok": 1,
"form_defaults": {
"service_form_id": 301,
"qi_form_id": 302,
"qi_field_id": "grade",
"revision": 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":"Programme Contracts is not enabled"} | Workspace flag or Contracts entitlement is disabled. |
{"error":"Permission denied"} | Contracts View or the required action permission is unavailable. |
{"error":"Module settings changed. Reopen Module Settings before saving."} | Revision is missing or stale. |
{"error":"Selected Job Form is unavailable"} | The resulting default is not an unarchived Job Form. |
Legacy application errors may be returned with HTTP 200. Check the decoded response for error, not only the HTTP status.
Behaviour and edge cases
- Stores one revisioned tenant setting. Validate the full resulting Form/field combination, including unchanged values. Each successful save increments revision.
- Changing inherited Service Forms invalidates pending previews. Already published Jobs and inspection snapshots retain their original configuration.
Side effects
- The service serializes writes on the tenant owner in a transaction. Validation, persistence, audit or TeamAccess outstanding-Job access failures roll back that transaction. Successful changed writes refresh linked Contract/Customer sync timestamps and shared mobile update markers, then invalidate CRM caches after success. These operations do not create schema or enable account features.
- Stores contract-programme-form-defaults and audits module_form_defaults_saved. QI changes advance inheriting Contract sync timestamps.
See it in Fieldmotion
CRM1
No direct caller was found in CRM1 source. This workflow is implemented by the opted-in CRM2 Programme Contracts workspace.
CRM2
Open Programme Contracts → Module Settings, change Forms and Save; filter for ContractProgramme_saveDefaults. The dialog reloads bootstrap before editing and sends that revision.
Related endpoints
ContractProgramme_saveConfig— Set or clear Contract-specific overrides.ContractProgramme_preview— Rebuild publication impact after changing inherited Forms.