Form definitions, recorded responses and exports
Insert an On Complete rule into one form
/a/Form_addOncompleteRule
Insert a serialized legacy rule into the first On Complete group of a Job Form.
When to use this endpoint
Use this when copying one rule from the On Complete editor into another Job Form. Read the target first: this is an insertion, not replacement of its complete automation definition.
Authentication and permissions
Authenticate with a signed API key (acting as its owner) or a logged-in CRM session on the routed account host. Session calls include the dispatcher’s CSRF value when configured. IDs refer to the authenticated tenant unless an explicit cross-account copy is described.
The handler adds no Forms page/role check. The dispatcher does not add a Form record-scope predicate; a screen’s CRM2 role controls are not evidence of an API restriction or a CRM1 permission requirement.
The account’s features2.disableFormEdits setting blocks this mutation with form edits are disabled for this account. A temporary user marked meta.is_tmp=1 bypasses that setting only.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
id | Positive integer-compatible ID | Yes | Job Form ID (type 0), not a Job ID. |
rule | JSON text decoding to an array/object | Yes | One rule object, including nested constraints when required. Native arrays are not the handler’s wire format. |
Example request
$result = FM_api('Form_addOncompleteRule', [
'id'=>'1042',
'rule'=>json_encode(['type'=>'setField','fieldID'=>'Result','value'=>'Checked']),
]);
Example response
{"ok":1}
Database numeric values can be JSON strings. Examples are representative; legacy application errors can use HTTP 200, so inspect the decoded response.
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: id"} | No positive ID. |
{"error":"missing parameter: rule"} | rule omitted. |
{"error":"missing or invalid parameter: rule"} | JSON does not decode to an array/object. |
{"error":"form does not exist or is not a Job form"} | No matching type-0 form. |
{"error":"form does not have a valid on_complete field"} | Stored first group cannot be extended. |
Legacy application errors may be returned with HTTP 200. Check the decoded response for error, not only the HTTP status.
Behaviour and edge cases
- Only type-0 forms are selected; archived forms are not excluded. The handler validates nested setJobStatus values against configured Job Status indexes, including explicit zero. This does not validate every rule type or referenced object.
- The rule goes before the first doNothing constraint in the first group. If no sentinel exists, it appends after the existing constraints. Other groups remain unchanged.
- An exact stored
[]initializes a default group ending in doNothing. Other malformed/empty first-group definitions are rejected. There is no batch, pagination or duplicate-rule detection. Retrying inserts again.
Side effects
- Updates on_complete and last_edited, invalidates the forms cache and creates an Undo baseline/snapshot within the checked Form transaction. It does not execute the rule or send its configured messages. A failed save/history write rolls back the SQL changes.
See it in Fieldmotion
CRM1
In the Job Form On Complete editor, copy a rule to another form. Filter Network for Form_addOncompleteRule; the rule is JSON.stringify output.
CRM2
The current copy-to-forms dialog uses Form_addMultipleOncompleteRule, even for a remaining single target; the currently open form can be changed in memory before its ordinary save.
Related endpoints
Form_addMultipleOncompleteRule— copy to several forms.Form_updateData— replace the saved onComplete definition.