Form definitions, recorded responses and exports
Export main and linked Job Table answers
/a/Form_exportDataAsCSVWithSubforms
Stream matching Jobs and their linked table rows in one flattened CSV file.
When to use this endpoint
Use the Form Data export with tables enabled. Group by Job ID and Source, and keep main rows separate from table rows; this is not one complete record per CSV line.
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.
Requires Report Form Data View via the same shared helper as the main-only export, retaining its role-less legacy allowance. No Job TeamAccess predicate is added by this Form handler.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
id | Positive integer-compatible ID | Yes | Parent Job Form ID; it must contain at least one field. |
dateFrom, dateTo | YYYY-MM-DD text | Yes | Both must match the numeric date format. Filters scheduled epoch strictly after local dateFrom midnight through dateTo 23:59:59; regex checks format, not a full calendar/reversed-range validator. |
customer_id | Integer-compatible ID | No | Nonzero exact stored customer_id; does not itself select Customer versus Asset. |
search | Text | No | General reference/user/Customer/Asset/serialized main-answer search. Blank disables it; not a nested DataTables search object. |
customer | Text | No | Customer or Asset name substring. This is a display-name filter, not a numeric Customer ID. Asset code matching is available in search, not this field. |
user_id, job_id | Integer-compatible IDs | No | Nonzero exact assignee and Job ID filters; zero disables each. |
department | Integer-compatible ID | No | Nonzero department filter; matching differs between the two exports. |
parent_id | Positive integer-compatible ID | No | Ordinary Customer Jobs whose customer_id matches, or whose saved customer_details.parent_id matches. Excludes Asset Jobs. |
Example request
$csv = FM_api('Form_exportDataAsCSVWithSubforms', [
'id'=>'1042','dateFrom'=>'2026-11-01','dateTo'=>'2026-11-26',
'customer'=>'Northwind','department'=>'0',
]);
Example response
Job ID,Source,User,Customer/Asset,Date of Meeting,Contract,Status,Form Num,Job Ref,"Result","Items:Item",Postcode,Street Address1,Street Address2,Town,Region,Country,Parent,Worker ID, Job Duration, Date Created, Job Finish,Job Type
Success is CSV bytes with an invisible UTF-8 BOM (omitted from the example). Preflight errors are JSON; failures after streaming begins may leave a partial file.
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 parent ID. |
{"error":"missing or invalid dateFrom or dateTo"} | Dates absent or wrong format. |
{"error":"invalid form or form does not exist"} | Missing definition or no usable fields. |
{"error":"subform definition missing or invalid"} | A linked definition cannot be decoded as an array. |
Legacy application errors may be returned with HTTP 200. Check the decoded response for error, not only the HTTP status.
Behaviour and edge cases
- UTF-8 CSV with BOM and attachment filename form_and_table_data_export.csv. Leading columns are Job ID, Source, User, Customer/Asset, Date of Meeting, Contract, Status, Form Num, Job Ref. A main field has one column; each direct subform expands to columns named ParentField:TableField. Trailing headers are shown literally in the example, including leading spaces on several labels.
- For each Job: emits one Source=main row, then Source=table rows aligned by table-row index across all linked tables. This is a horizontal alignment, not a Cartesian join or an independently identified row per table. Missing table cells and ordinary main fields on table rows are blank. Even retained unlinked table arrays contribute to the maximum number of emitted table rows.
- Preflights every direct linked subform definition before streaming. Missing/malformed definitions return a controlled error; nested subform cells are blank rather than recursively exported. No completion/status or archived-form restriction.
- Streams 100-Job batches ordered by (scheduled epoch, Job ID), continuing after that pair. All original filters remain active across batches. No caller pagination controls and no consistent snapshot: concurrent edits can affect remaining rows.
- search matches reference, assignee name, Customer/Asset names, Asset codes and serialized main answers, not arbitrary table answers. customer matches Customer/Asset names. Unlike the main-only export, department is an exact Job department filter. Customer/Asset display caches are keyed by both type and ID.
- Resolves Asset/Department answer names, comma-joins multi-selects, converts calculation formats, emits image URLs/embedded/no image markers and signature supplied. Table stock cells summarize quantities and stock names; these are display values rather than a lossless serialized-answer backup.
- Both main and table rows align current address, parent, worker, duration, raw creation/completion datetime and Job Type values with their header columns. Duration uses full datetimes, including overnight/multiday intervals; missing, malformed or negative elapsed values are blank.
Side effects
- Reads database rows and streams output; does not change Jobs, stock, definitions or export checkpoints.
See it in Fieldmotion
CRM1
In Reports → Form Data, export with tables enabled. Filter Form_exportDataAsCSVWithSubforms; id is the parent form, not a table.
CRM2
In Form Data’s export dialog, enable tables. Its POST selects extra=/Form_exportDataAsCSVWithSubforms and passes form ID, dates, label-based customer and numeric filters.
Related endpoints
Form_exportDataAsCSV— download main answers with a different column layout.Form_exportTableData— export one table across its single parent form.