Report schemas
Updated
A schema holds what several standard reports share: the source, the additional sources, the filters, the period and the measures: revenue, cost of sales, margin and its percentage. Each report built on it keeps only its own part: its groupings, highlights and charts, and the measures it shows. Margin is then written once, and a fix to the schema reaches every report built on it.
← Developer wiki · Report variants and reader settings · Report modules
A schema#
A schema is a standard report (Reports/Standard/<Name>.userreport.json) whose layout says "schema": true. Its columns are the measures. Its dimensions say how each additional source reads a grouping, so the reports do not repeat factPaths:
{
"schema": true,
"root": { "kind": "Register", "metaId": "103cdb23-…" },
"facts": [ { "id": "f1", "root": { "kind": "Register", "metaId": "7e0b4d85-…" }, "periodPath": "MovementDate",
"filters": [ { "n": 1, "path": "Value", "op": "lt", "value": 0 } ] } ],
"columns": [
{ "id": "rev", "kind": "field", "path": "Amount", "agg": "Sum", "format": "money" },
{ "id": "cost", "kind": "row", "factId": "f1", "expr": "0 - [Value]", "agg": "Sum", "format": "money" },
{ "id": "margin", "kind": "group", "expr": "[rev] - [cost]", "format": "money" },
{ "id": "pct", "kind": "group", "expr": "([rev] - [cost]) / [rev]", "format": "percent" }
],
"dimensions": [
{ "path": "Item", "factPaths": { "f1": "Item" } },
{ "path": "MovementDate", "factPaths": { "f1": "MovementDate" } }
],
"period": { "path": "MovementDate", "relative": "THIS_YEAR" }
}
A schema is not listed among the reports, nor offered by the assistant. Only those who may change its model see it in Reports, where it opens and runs like any report.
A report built on a schema#
The report's file names the schema by id and lists what is its own. A column { "measure": "margin" } is the schema's measure; any other key next to measure overrides that key of the measure ("caption", "hidden", "format"):
{
"extends": "<the schema's metaId>",
"columns": [ { "measure": "margin", "caption": "Loss" }, { "measure": "pct" } ],
"groupRows": [ { "path": "Item", "sort": "asc", "sortBy": "margin" } ],
"highlights": [ { "columnId": "margin", "op": "lt", "value": 0, "color": "red" } ]
}
| In the report's file | What the stored report gets |
|---|---|
| nothing | the schema's value: root, sources, filters, period, options, columns |
columns |
these columns; a measure a group formula reads ([rev], [cost] for margin) comes along hidden |
facts |
the schema's sources; one with the same id replaces the schema's |
filters |
the schema's filters; one with the same n replaces the schema's |
an object (options, period, visual) |
the schema's object with the report's keys over it |
a key set to null |
the key removed: "period": null runs without the schema's period |
root |
must be the schema's; a report cannot read another source |
groupRows, groupCols |
the report's, each grouping the schema has a dimension for gets its factPaths |
A standard variant (variantsJson) can say extends too, and is built the same way. A schema can itself be built on another schema ("schema": true next to extends): its dimensions are the other's and its own.
Where it is built#
The layout is built when it is installed, and the stored report is whole: the window, mailing, a dashboard tile, the mobile desk and the assistant run it as any layout. It keeps "extended": "<schema id>" to remember where it came from.
- Workspace import and a workspace file applied on a stand build every report whose file says
extends, schemas first. A report whose schema changed in the same import is rebuilt: its stored layout is compacted against the schema as it was, then built on the new one. - Saving a schema in the report builder rebuilds the reports built on it in the same way.
- Saving a report built on a schema in the builder stores it whole; it stays built on the schema.
- Workspace export writes such a report compact:
extends, its own keys, and{ "measure": id }for every column equal to the schema's. A report whose root is no longer the schema's is written whole.
A report that cannot be built is left as it was stored, and the import lists a warning: its schema is not installed, it names a measure the schema does not have, or schemas extend each other in a circle.
The assistant#
compose_report builds a report from a schema when no ready report answers the question: the schema's measures (by id or caption) by the groupings asked for (a dimension's path or caption, or any field path of the source; a date with a step: Month…), for a period or the schema's own. It runs as a report built on the schema would, with the caller's rights. Called without a schema it lists the schemas the caller may read, with their measures and groupings. With saveAs the layout becomes the caller's own draft report in Reports and opens; it keeps extended, so it can be put into a model later as a report built on the schema.
What a report cannot do#
- Remove a source or a filter of the schema. It can replace one with the same
idorn, or switch a filter off with"use": false. - Read another root. A margin by customer, for example, stays rooted at the sales documents, because the cost register has no customer.
Code#
| Piece | Where |
|---|---|
| Building and compacting a layout | ReportExtends (src/ZuloOne.Core/Services/UserReports/ReportExtends.cs) |
| Building the stored reports; the compact file | StandardReportExtends.ExpandAsync, StandardReportExtends.ForFile |
| Lists without schemas | UserReportsController (isSchema on a list item), AssistantUserReportRunner |
| Tests | ReportExtendsTests |
Same topic for other readers: User