Parsware
All articles

Tables and data

States and reasons: where a record is in its life

Every table has a State and a Reason. Design the lifecycle your records move through, with a reason under each state, colours and icons that read at a glance, and numbers from your publisher's range.

The States & Reasons page in dark mode: Active with Scheduled and Running, On hold in amber with Waiting for a trainer, and Inactive with Completed and Cancelled in red, each with its colour, icon and value, next to the title "States and reasons"

A course is scheduled, then running, then over. An invoice is open until it's paid or written off. Nearly every table needs to say where a record is in its life, and why. So every table in Parsware already has two fields for it: State and Reason.

A new table starts with two states, Active and Inactive, each with one reason of the same name. You can't delete the fields. You can design what's in them. Here we give Training Course a lifecycle of its own. Every picture is the real product.

Design the lifecycle

Open the table and choose States & Reasons in its rail. Each state is a card, and its reasons sit inside it:

The States & Reasons page for Training Course: Active in green with reasons Scheduled (blue, calendar icon, value 0) and Running (green, play icon, 270160001); On hold in amber with value 270160000 and reason Waiting for a trainer (270160003); Inactive in grey with reasons Completed (1) and Cancelled in red (270160002)

Here the course has three states:

  • Active, because it's Scheduled or Running.
  • On hold, because it's Waiting for a trainer. This is a new state, added with Add state.
  • Inactive, because it was Completed or Cancelled.

Active and Inactive are yours to rename, and so are their first reasons. Here they became Scheduled and Completed.

Each state and each reason can have a colour and an icon, from the same pickers an option set uses. They're optional, but they're what lets someone see which courses are still running without reading every row.

Order matters for states. New records start in the first state, with its default reason. Leave the default on First reason and it's whichever reason is at the top. Drag a card by its grip to reorder the states, or a row to reorder a state's reasons. Here On hold was dragged up above Inactive.

A reason belongs to one state, so you can only drag it within that state. Moving Cancelled under Active would be a different lifecycle, not a reordering.

The numbers

What a record stores is a number, as with an option set:

  • Active is 0 and Inactive is 1, on every table, so they mean the same everywhere.
  • Anything you add is numbered from your publisher's range. Contoso's starts at 270160000, so On hold got 270160000 and Running 270160001. Two publishers extending the same table can't give the same number two meanings.
  • A number is never reused. Remove On hold, add another state, and it gets a fresh number. A record somewhere may still hold the old one, and reusing it would quietly change what that record says.

You can remove a state or a reason while records still use it, because a business changes and waiting for every old record to be migrated would freeze the design. Those records show the bare number until someone sets them to a current state.

On the form

State and Reason are fields like any other, so you place them on the form in the form designer. The best place is the form's header, the strip beside the record's name that stays put whichever tab is open. Drag both in.

Header fields are read-only by default. That's usually what you want, since the header is for reading. To let people change the state right there, select each field in the header and untick Read-only in the Properties panel. Then the State is a dropdown in the record's colours:

A course form header: Training Course - Excel for Finance, with State showing Active in green and its list open offering Active, On hold in amber with a pause icon, and Inactive in grey, and Reason showing Scheduled in blue

The reason follows the state. Choose Inactive and the Reason moves to Inactive's default reason, and its list offers only Inactive's reasons:

The same header after choosing Inactive: Reason shows Completed, and its list offers only Completed and Cancelled, Cancelled in red

Offering Running on a course that's over would make no sense, so the form doesn't. Put the course on hold instead, save, and the header reads at a glance:

The saved header: State On hold and Reason Waiting for a trainer, both in amber with their icons

In a list

Add State and Reason as columns in the table's view, and the list shows every course's standing in its colours:

The Training Courses list with State and Reason columns: Forecasting with Python, Active, Scheduled; Power BI Basics, Inactive, Completed; Intro to SQL, Inactive, Cancelled in red; Project Management Essentials, Active, Running in green; Excel for Finance, On hold, Waiting for a trainer in amber

Because every table has its State in the same place, anything that needs to tell open records from closed ones, a list or a rule, looks in the same place whatever the table.

The lifecycle as the table stores it

States and reasons are part of the table's own document, beside its fields. The course's lifecycle from the first picture reads like this:

{
  "logicalName": "con_trainingcourse",
  "statusValueBase": 270160000,
  "nextStatusValue": 270160004,
  "states": [
    { "value": 0, "displayName": "Active", "defaultReason": 0 },
    { "value": 270160000, "displayName": "On hold", "defaultReason": 270160003 },
    { "value": 1, "displayName": "Inactive", "defaultReason": 1 }
  ],
  "reasons": [
    { "state": 0, "value": 0, "displayName": "Scheduled" },
    { "state": 0, "value": 270160001, "displayName": "Running" },
    { "state": 270160000, "value": 270160003, "displayName": "Waiting for a trainer" },
    { "state": 1, "value": 1, "displayName": "Completed" },
    { "state": 1, "value": 270160002, "displayName": "Cancelled" }
  ]
}

The colours and icons are left out here to keep it short. Each reason names the state it belongs to, which is how the form knows to offer only Inactive's reasons once you choose Inactive. The order of states is the order you dragged them into, and the first is where new records start. nextStatusValue only goes up, which is how a removed state's number is never handed out again.

Inactive means read-only

The built-in Inactive state does more than label a record. Once a record is inactive it is read-only: it opens with a note saying so, no field takes typing, and the command bar offers Activate and nothing else that changes it. This is the rule that lets you stop using a supplier, a product or a course without deleting it, so the invoices and enrolments that name it still make sense.

The lock is the server's, not just the form's. An update sent through the API to an inactive record is refused with the same message, naming the field it tried to change. Automation is the exception: a process, a function or a solution import can still write to an inactive record, which is how a sample's demonstration data can arrive already inactive.

To close a record, use Deactivate on the form or on a selection in the list. It asks for the reason, starting on Inactive's default, and changes only State and Reason. If you have unsaved typing, Deactivate waits until you save, so nothing you typed is lost when the record closes.

Your own states, such as On hold, stay editable, because they are usually stages somebody still has to finish. If one of them should lock the record too, add a server rule that refuses updates in that state. The Suppliers sample in the platform's sample solutions shows the whole Deactivate and Activate cycle.

Views that hide what's finished

Most lists people work from should show only what is still in play. A view filtered on State does that, and because Active is 0 on every table, the filter reads the same everywhere:

{
  "logicalName": "con_trainingcourse_active",
  "displayName": "Active courses",
  "entity": "con_trainingcourse",
  "viewType": "Public",
  "columns": ["con_name", "con_starts", "con_level", "state", "reason"],
  "filterGroup": {
    "connector": "And",
    "conditions": [{ "field": "state", "operator": "Equals", "value": 0 }]
  }
}

Keep an All courses view beside it, with State and Reason as columns. That is where somebody goes to find a finished course and bring it back. A filter on Reason is one of Running, Waiting for a trainer gives a team a short list of what needs attention today.

Rules that depend on the reason

Often a reason carries an obligation. A cancelled course needs a cancellation note, so that the people who booked it can be told why. A server rule says so once, and it holds whether the course was cancelled on the form, in an import or by an integration:

// 270160002 is the Cancelled reason on Training Course.
if (getValue('reason') == 270160002 && isEmpty(getValue('con_cancellationnote'))) {
  throwValidationError('A cancelled course needs a cancellation note.');
}

state and reason are read like any other field. As with an option set, compare the numbers, not the labels, so the rule keeps working when somebody renames Cancelled or opens the app in Persian. Add a server validation rule shows how to register a rule like this one before every save.

Processes move records through their states

When a record's life is a series of decisions, an approval process is usually what moves it from one state to the next. A purchase order starts Open, moves to Approved when two people have signed it off, or to Closed with the reason Refused when one of them says no. The people deciding never pick the state by hand: each decision writes it.

That is the cleanest arrangement for anything audited. The form shows the state read-only in the header, the process is the only thing that changes it, and the record's history says which step changed it and when. Parallel sign-off builds exactly that purchase order, and Processes that actually run explains how a step writes back to the record.

Designing a lifecycle that lasts

  • Keep states few. A state is a question people ask of every record: is it still going? Three or four is usually plenty. The detail belongs in reasons.
  • Make reasons answer "why". Completed and Cancelled are both Inactive, for different reasons, and a report on why courses end needs exactly that split.
  • Put the state people will look for first. New records start there, so it should be the state most records are in when they are created.
  • Leave Inactive as the end. It is the state that locks a record, so it is where finished work belongs.
  • Show both in the header, with Owner, so everybody opening a record sees where it is, why, and whose it is. Forms that fit the job arranges the header.

Questions that come up

Should I deactivate or delete? Deactivate anything other records still name, or anything somebody may ask about later: a supplier on old invoices, a course people attended. Delete only what was a mistake. An inactive record drops out of the everyday views and stays findable in All.

Can a record go back from Inactive to Active? Yes, with Activate on its form. It reopens editable, in the Active state. If reopening should be rare, say so with a role: a role can allow reading a table without allowing changes, and Security roles in practice shows how.

Does a lookup still offer inactive records? A lookup's search follows the table's lookup view, so filter that view on State = Active if retired records shouldn't be picked any more. Lookup views and quick find explains where to set it.

Do states travel to Production? Yes. They are part of the table, so they go with it in the solution, with their numbers. A record in Production that says 270160000 means On hold there too.

Why this isn't an option set

An option set is one list that many tables share. A lifecycle is the opposite. "Active" on a course and "Active" on an invoice aren't the same choice, and if they came from one shared list, changing the course's lifecycle would change every other table's too. So states and reasons belong to their table. You edit them with it, and they travel with it when the solution is exported.

Next: reference numbers that number themselves, the auto-number field.