Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics 365 | Integration, Dataverse...
Suggested answer

Display all Stages of a Business process flow with conditions

Posted on by 100

Hi everyone,

 

Context:

 

I have a business process flow which contains multiple Stages which require approval before moving to a subsequent stage. The approvals are managed by a Flow step within each Stage.

Per the example below, you can see there is a Flow step for more than one Stage.

BPF-1.png

BPF-2.png

However, users can still select the run flow button on any stage. I can create a condition in power automate which skips the flow if the previous stage was not approved. But ideally, I would prefer it users could not select the run flow button in the first place. As far as I am aware, it is not possible to hide or lock the Run Flow button ( I have a separate post on this here: https://community.dynamics.com/365/f/dynamics-365-general-forum/479154/lock-hide-run-flow-button-in-business-process-flow)

BPF-Workflow.png

 

One option is to add a condition in business process flow editor to prevent the user from navigating to any subsequent stages until the approval triggered in the previous stage is marked “approved”. However this is also not ideal, because it hides the Stage from the form until the condition is met.

 

Question:

 

Does anyone know if it is possible to display all Stages of a Business process flow, irrespective of the conditions?

  • Ami K Profile Picture
    Ami K 100 on at
    RE: Display all Stages of a Business process flow with conditions

    Apologies Eiken  for not responding sooner. Thank you for your support on this.

    Below is my current method ( no code )

    1. I have created a yes/no field in my Dataverse table for each approval stage. The field updates to “Yes” via Power Automate if the stage is approved (using Lisa Crosbie’s tutorial: https://youtu.be/0tNQLj7uKwQ?t=1).

    2. I have created a condition between each stage to validate whether the previous Stage was approved using this field.

    3. In the example below, the user cannot proceed to the “G6 approval” stage unless the “Is Approved by G7” field equals “Yes”


      screenshot-1.jpg




    4. This process is repeated for subsequent stages. For example, the “Strategy Director Approval” stage cannot proceed unless the “Is Approved by G6” field equals “Yes”


      screenshot-2.jpg






    5. If the condition is not met for each stage, then I recreate the entire business process flow without the conditions. This purely to ensure the entire Business Process Flow still appears in view. There is nothing functional that happens here.

    screenshot-3.jpg

    By doing this, the user cannot bypass the current stage because the run flow button is hidden in subsequent stages by default.

    screenshot-4.jpg

    screenshot-5.jpg

  • Eiken Profile Picture
    Eiken on at
    RE: Display all Stages of a Business process flow with conditions

    Hi,

    I am afraid that there is something wrong with my code.

    It run failure now.

    I'll let you know if i find another way to hide it.

  • Suggested answer
    Eiken Profile Picture
    Eiken on at
    RE: Display all Stages of a Business process flow with conditions

    Hi,

    The getElementById get all button whose id is "MscrmControls.Containers.ProcessStageControl-flowButton_1_flowButton".

    You can us Js to select which one you want. 

    pastedimage1677547219481v1.png

    These variables store the current bpf's stage name and id.

    You can show the run flow button based on there value.

  • Ami K Profile Picture
    Ami K 100 on at
    RE: Display all Stages of a Business process flow with conditions

    Thanks for this Eiken.

    A couple of questions when you have time:

    1. On reading the script, am I correct in that this code will hide the run flow button on all inactive stages?

    2. I am not very knowledgeable on JS script but I notice these variables are declared, but are not used anywhere in the function?

    var activeStage = Xrm.Page.data.process.getActiveStage();
    var stageId = activeStage.getId();
    var stagename = activeStage.getName();

  • Suggested answer
    Eiken Profile Picture
    Eiken on at
    RE: Display all Stages of a Business process flow with conditions

    Hi,

    You can add Javascript to hide the button,

    I am testing to hide the button when on load.

    Please refer to my following steps.

    pastedimage1677491443388v1.png

    pastedimage1677491468299v2.png

    function showstage()
    {
    Xrm.Page.data.process.addOnStageChange(getStage); 
    getStage();
    }
    
    function getStage()
    {
        setTimeout(function(){
            parent.document.getElementById("MscrmControls.Containers.ProcessStageControl-flowButton_1_flowButton").style.display="none"
        },100)
    var activeStage = Xrm.Page.data.process.getActiveStage();
    var stageId = activeStage.getId();
    var stagename = activeStage.getName();
    
    }

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans