Case study · 03 / 12
Management reporting where a new report is a data change
A case study — Enterprise Management Reporting: Data Capture
Summary
| Problem | Monthly, quarterly and ad hoc management reports were assembled by hand from spreadsheets and email, with no record of who supplied which section, who approved it, or what changed between rounds. |
|---|---|
| Constraint | Everything had to live in the client's own SharePoint, run as the signed-in user with no elevated service, and stay portable to Dataverse — while every new report, section or field had to be possible without a release. |
| Solution | Two SPFx web parts and an application customizer: a Data Capture screen driven by per-topic JSON definitions, a Form Designer that writes those definitions, and a multi-approver review model over seven lists and one library. |
| Outcome | Release 1.18.1.0 packaged as the production release, after two independent pre-production reviews. 1,410 tests across 55 suites; build 0 errors, 0 warnings. |
| Role | Architecture, data model, both web parts and the customizer, provisioning and permission scripts, deployment runbook, user guides per role, release and review process. |
| Stack | SPFx 1.23.2 (Heft) · React · TypeScript · PnPjs · Fluent UI · SheetJS · Jest 30 · PnP.PowerShell · Node 22 |
1. The problem
A management report is rarely one person's document. A monthly report for an energy-sector organisation has a general section, trading and export figures, development-project progress, and supporting commentary — each owned by a different person, each needing sign-off from different approvers, and all of it due on the same date.
Done by spreadsheet, the questions that matter cannot be answered: which version did the approver actually see, who changed the figure after approval, why was a section sent back, and is this quarter's table comparable with last quarter's when someone added a column in between.
The brief was a capture system where the *report itself* is configuration. A topic — a monthly report, a quarterly review, a one-off board request — is a definition stored in SharePoint. Adding a topic, a section or a field is a data change, not a code change.
2. The constraints
The web part never elevates. It runs in the browser as the person signed in, through PnPjs, so every read and write is that person's own. What the screen offers is decided by *seats* — who owns a topic, who edits which section, who approves it — but what a person *can* do is decided by SharePoint permissions. The two are kept deliberately separate: seats change monthly and are a list a human edits; permissions are site configuration. A custom permission level, *Contribute without delete*, means nobody removes a trail line or a section's history through the list itself.
It must port to Dataverse. The solution was extracted from an earlier Power Apps code-app prototype, and the data model documents, list by list, the Dataverse table and column each SharePoint column becomes. The domain modules — the definition, periods, seats, stages, values, export — know nothing about lists or columns, so they port unchanged.
It must survive the 5,000-item list view threshold. Five of the lists grow every period. Past 5,000 items SharePoint refuses any filtered read it cannot serve from an index — not slowly, outright.
3. Architecture
Web parts Data Capture the period screen, review, completion
Form Designer design, preview, publish, seats — no JSON by hand
Customizer EMR header the application's own header; SharePoint chrome hidden
Lists Forms · Settings · Approvers · Submissions · SectionValues
Approvals · Reviews + the Files library
Stages Data entry → Section review → Final approval → CompletedA port-and-adapter split carries the whole design: CaptureRepository is the port, one implementation runs over any list store, PnPjs sits underneath for SharePoint, and an in-memory store stands in for tests. The screen's decisions live in a pure screenModel tested against that in-memory repository, which is how 1,410 tests can run with no tenant at all.
Topics are versioned. Each published definition is a new row; the highest published version wins for new periods, and a period stays pinned to the version it was started against — so redesigning a form never rewrites a report already in flight.
A completed period becomes an output. When the final approver signs off, a folder appears holding an Excel workbook of every section and a copy of every attachment, linked from the Completed card.
4. The interesting decisions
4.1 Review as one act per approver, not one click per section
The first approval model was a button per section. It was replaced by a review: each approver answers every section they hold — approve, or send back with a required comment — each answer saved as a draft as it is given, then submits the review once, with an optional overall comment.
The topic waits for every approver. When all have submitted, it moves to final approval if every section was approved, or back to data entry a round later if any was sent back — with each reviewer's comments on the cards. Two site switches control whether submitted reviews are visible before everyone has submitted, and whether a submitted review can be withdrawn.
The edge this creates is a seat change mid-round: if an approver is removed, the round could wait forever on someone who is no longer there. The topic owner and the final approver can therefore move on a round that a seat change left with nobody to wait for.
4.2 Every write carries an etag
Two editors on one section at the same moment is the normal case near a deadline, not an edge case. Every save carries the row's etag as an If-Match header, so the second save is refused rather than silently overwriting the first. Approvals are derived from the trail rather than stored as a flag that could drift from it.
4.3 Completed is recorded before the output is written
Generating the output — the workbook and the copied attachments — can fail halfway. The period is therefore marked Completed *first*, and the output written second. A failure leaves a completed report with a working Retry, rather than an approved report stuck at the final stage with no way forward.
4.4 Periods on the local calendar
A period key such as 2026-10 must be computed on the user's calendar, not UTC. At UTC+4, half past midnight on 1 October is still 30 September in UTC — so a UTC calculation files the first half-hour of a month's work into the previous month. The fix is local-calendar arithmetic, and the test suite runs pinned to UTC+4 and UTC+5 time zones so a regression to UTC fails a test rather than a month-end.
4.5 Indexes, and pages of 2,000
Schema version 8 adds nine indexes and nothing else — one on every column a query filters by, on the five lists that grow. Every query is also read in pages of 2,000 in id order, never a single 5,000-row read. An index holds no data and changes none, and the provisioning script never takes one off, so the change is safe to apply to a live site.
4.6 Features off until a site turns them on
Thirteen features — the periods view, copy from a previous period, refresh from a source workbook, multiple files per field, the designer's section editing and others — are registered in one place and stored as setting rows. Every one is off on a new site. One that is off is not drawn, and is refused if reached by its address. A new site shows the core workflow and nothing else; each extra is turned on by a site owner when the business is ready for it.
4.7 A dependency chosen for its security, not its registry
The spreadsheet library's copy on the npm registry is frozen at a version with known advisories; current releases are published only on the vendor's own CDN. The build fetches it from there, the decision is documented with its reasoning, and the library is loaded only when someone first reads a workbook or downloads one — so it costs nothing on a page that never uses it.
5. Outcome
Release 1.18.1.0 is packaged as the production release: SPFx 1.23.2 on the Heft toolchain, 1,410 tests across 55 suites, build and lint 0/0, a deterministic ship build, and npm audit clean for production dependencies.
It reached that point through two independent pre-production reviews:
- Review 01 verified 150 findings — 4 High, 40 Medium, 106 Low — refuted 14, and returned *Go with conditions*. The safe fixes shipped in the next release; the data-integrity findings in the one after.
- Review 02 checked the release candidate against every item marked fixed: 52 of 60 fixed, 8 partly, none regressed, and no new finding blocking production.
Around the code sits what an operations team needs to run it: a provisioning script that is idempotent and verifiable, a deployment runbook with first-install, upgrade, rollback and sandbox-to-production parts, a permission model per role, a retention policy, a support handover, a user guide for each of the five roles, and an administrator's guide.
6. What I'd take from this
Make the report configuration, and the release cadence stops being the business's problem. A new topic, section or field is a definition row. The business changes its reporting without waiting for a developer.
Separate what the screen offers from what the platform permits. Seats decide the buttons; SharePoint permissions decide the outcome. Keeping them apart is what lets seats change monthly without anyone touching site security.
Write the failure path before the happy path. Completed-before-output, etags on every save, a way to move on when a seat empties mid-round — each exists because the question *"what happens when this goes wrong halfway?"* was asked before the feature shipped.