Turns out we can’t use process.setStatus freely to finish a business process at any time – it has to be in the final stage. Otherwise, we can only abort a process.
Come to think of it, it is neither too obvious, nor too counter-intuitive. Either way, the code below works, it seems:
formContext.data.process.setStatus(“finished”, result => {
if(result == “invalid”) formContext.data.process.setStatus(“aborted”);
});