State machines are a new concept in D365O, and a very welcome feature. Previously, the control of status fields was handcrafted in code, which could be often hard to read as there was no obvious pattern to follow; having said that, we will always look at a similar standard example to our case and use that idea. This is not plagiarism, it is good practice. It is a good general rule to seek examples in standard code, as there is a much higher chance that another developer will understand the code we've written.
State machines allow us to define in metadata how the status transitions from an initial state to its final state. These rules are then enforced by code that the state machine will generate.
There is a restriction though. There must be one initial state and one final state. When we are at the final state, there is no going back. If we take the sales order status, we have two final states:...