The other week I finished up a project to get a spreadsheet of historical training sessions into Dataverse, where each session is a record (i.e., a row) in a table. There are 900 and some of them, and each one is just a group code (unique identifier) and a date. Normally a person records a session by clicking through a detailed form and its business process flow (BPF) in a large, heavily customized model-driven app. I was not doing that 900 times, so I instead wrote a small .NET console app.

This was a quick and dirty, one-off backfill, out of band from the established process.

What Does “Finished” Even Mean?

Saving a session through the form does a lot more than create one row. It also creates attendance records for every active member of the group and updates some flags and misc. totals, and then there’s the BPF, which eventually gets marked “Finished”. So I spent time sifting through the morass of dozens of tables, the BPF definitions, workflows - cloud (i.e., Power Automate) and classic - table metadata, and all the relevant dependencies.

The SDK doesn’t run any of the form’s JavaScript, but the server-side stuff still runs. In other words, some cloud flows trigger off Dataverse events tied directly to the BPF I’m trying to bulk import.

How It Works

The app reads the workbook with ClosedXML and does the rest through the Dataverse SDK. It has a mode that just checks the workbook offline (dates, duplicate group codes, etc.), and by default it does a live dry run that writes nothing. it only does the real thing when you say so. This is where I likely “overdid it” (or rather, my AI assistant urged me to overdo it). Nothing gets written unless every row passes the dry run (atomicity, sort of), and that caught 20 bad (missing - heh) “group” codes in my first 100-row test file.

A commit runs these in order:

CreateNewParents(plans, metadata, options);
CreateOrUpdateAttendance(plans, metadata, options);
EnsureBpfAtDocumentStage(plans, metadata, options);
FinalizeParentTotals(plans, metadata, options);
CompleteSessions(plans, metadata);
VerifyCommittedPlans(plans, metadata, options);

Something I had to train myself on right away when I took this project on: the session and its BPF are separate records (along with every other “event”, as we call them, which is the business process flow), because a custom entity (table) is generated when you create the BPF. The importer creates the BPF instance itself at the documents stage and moves it forward by stage ID, since this process has two stages named “Validation”.

I think automating stuff is fun, and also a sort of miracle. I also think there are plenty of things/processes that don’t need or lend themselves to automation, at least not easily. Spending a weekend automating a 10-minute task is a weekend I never get back. Determining this micro break-even point can be difficult. This was not one of those cases. Manually clicking through that form 900+ times myself (or having the business do it themselves) is how repetitive stress injuries occur. Uploading the spreadsheet directly to Dataverse was also not an option because of the side effects and required associated records. A small .NET console app was well worth it.

In the end, I ran it for real with 80 rows in the sandbox/dev environment first, which came out to a bit over 3,000 attendance records, and it all checked out. Lovely. Then the full 900 and some in production, and nothing broke.