To show the status of a flow, we first have to know what flow is started and when it is ended.

A really nice solution is mentioned here: https://xrmvision.com/en/blogue/monitor-flow-runs-power-automate-model-driven-app/

There is also a rather easy solution that works fine as well: the moment the flow starts, you set a status field (like “FlowIsRunning”) to Yes on the record. And when it is ended (successful or in an error), you may set the status of the record to No.

Next we want to show the status of the flow on that record. I created a script that is being started onLoad of the form and that is polling the status each 2 seconds. When the FlowIsRunning status is set to Yes, a message is displayed. And that massage will be removed if FlowIsRunning is set to No. I have created the following script:

function sleep(ms) {
    return new Promise(resolve => setTimeout(resolve, ms));
}
  
async function checkStatus(e){

    var formContext = e.getFormContext(); 
    var id = formContext.data.entity.getId();
 
    while (true) {

        await Xrm.WebApi.retrieveRecord("opportunity", id).then(
                
            function success(result) {

                if (result.os_flowisrunning)
                    formContext.ui.setFormNotification("Please wait until the flow has ended...", "INFO", "FlowMessage");
                else
                    formContext.ui.clearFormNotification("FlowMessage");
            });
        
        await sleep(2000);
    }
}

I’m not a Javascript coding expert. So if anybody has suggestions, please let me know! (elowy@grootcrm.net)