When to use this endpoint

Use this when selecting a different invoice template/form without changing field values.

Authentication and permissions

The request must use a logged-in CRM session or valid signed API credentials and is scoped to that tenant.

Users whose legacy crm_access mask contains bit 64 receive {"error":"no permission to access api"}. No record-owner check is made.

Parameters

ParameterTypeRequiredDescription
idIntegerYesActive invoice ID.
valIntegerYesForm ID. Zero clears the selection; positive IDs must exist and have form type 7.

Example request

$result = FM_api('Invoice_setForm', ['id' => 981, 'val' => 17]);

Example response

{
  "ok": 1
}

Errors and unusual responses

ResponseCondition
{"error":"not logged in"}No authenticated tenant context is available. Invalid signed credentials can be rejected by the dispatcher before the handler runs.
{"error":"form does not exist"}A positive form ID is absent.
{"error":"wrong form type"}The selected form is not an Invoice form.
{"error":"cannot edit invoices that are marked Paid"}The invoice is Paid.

Legacy application errors may be returned with HTTP 200. Check the decoded response for error, not only the HTTP status.

Behaviour and edge cases

  • An unchanged form returns warning: no change needed. The route does not clear or translate existing custom-form values.

Side effects

  • Updates form_id and last_edited. It does not fire Invoice_edit.

See it in Fieldmotion

CRM1

Job Invoice and the main invoice editor call this route.

CRM2

No direct production CRM2 caller was found for this route.

Related endpoints