web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Preventing BPF to move to next stage without satisfying the condition on the first stage

(0) ShareShare
ReportReport
Posted on by 108

Hi All,

I have a scenario in the Business process flow to not to move to the next stage until it satisfies the condition in the current stage.

I have 5 stages and in each stage, I have a condition to meet. Once it is met, the BPF should allow it to move on to the next stage.  

The first BPF stage name is "verify Contact". 

This stage is having a field "verify Contact" in the BPF header. This has a drop-down list and when the user selects "Approved", it should get move to the next stage (or) else it should throw an error as  " Since Verify contact is not approved, you cannot move to next stage".

Can anyone please help me with how to do this in javascript?

please refer to the screenshot for more details.

pastedimage1564700976130v2.png

*This post is locked for comments

I have the same question (0)
  • Verified answer
    RaviKashyap Profile Picture
    55,410 Moderator on at

    Hi,

    You can trigger a real time workflow on stage change where you can check the field value and if it is not approved throw your message.

    Refer these blogs-

    www.magnetismsolutions.com/.../how-to-run-workflow-on-business-process-flow-stage-change-in-dynamics-365

    survivingcrm.com/.../

    Hope this helps.

  • Poornimaa Profile Picture
    108 on at

    Hi Ravi,

    Thanks for your answer. The Workflow works perfectly well for the first stage. But it is not working for the next BPF stages. It is checking all the conditions in the first stage itself.

    (Eg) In the workflow, if there is only one condition, "Verify Contact = approved", this is working fine. When I run the workflow and when the condition satisfies it is allowing me to navigate to the next stage.

    But if the workflow contains 2 conditions (1st BPF header field ---> Verify Contact = Approved" and 2nd BPF header field ---> Verify Account = "Approved") then the workflow is not working fine. it is checking both the condition in the first BPF itself. (refer the image in the Question above)

    Can you help me with this? or is there any javascript I can write to.. ?

  • RaviKashyap Profile Picture
    55,410 Moderator on at

    Hi,

    As the fields are on different stage, you need to create asepoarate workflow with verify account condition and set it on second stage. This is becuase this implementation only works for a particular stage.

  • Poornimaa Profile Picture
    108 on at

    Thank you so much, Ravi. Your help is much appreciated. !!

  • Poornimaa Profile Picture
    108 on at

    Hello,

    The above solution worked well, but there is another problem.!!

    The BPF throws me an error when I'm not selecting "Approved" and try to move to the next stage, which is good.

    But it is not allowing me to save on the first stage itself if it is not approved. There is a scenario if all the fields in that first stage are filled, then make the status as Approved, or else "waiting for the information from Contact" (or) "waiting from Customer" option needs to be selected.

    When I'm selecting one of these options and click "SAVE", it is showing the error "You cannot move to next stage............", but actually here I'm not moving to the next stage, but just saving the information. 

    Can you please help me?

    pastedimage1564965347277v6.png

  • Suggested answer
    RaviKashyap Profile Picture
    55,410 Moderator on at

    Hi Poornima,

    This should not happen if you have register the workflow only on stage change for that stage. It looks like you have some other code/logic which try to change the stage to next on saving the record which internally triggering your workflow.

    Can you check if this is the case.? If you can't find anything which is changing the stage, then disable the workflow on stage change and then update the record and check if the stage gets changed. This will confirm if there is some code which is changing the stage automatically or not.

    Hope this helps.

  • Poornimaa Profile Picture
    108 on at

    Hi Ravi, thanks for your response.

    I disabled the workflow and I changed the status to "Waiting for customer information " and then when I click on the "SAVE", it is all fine.

    But when I enable the Workflow, it is behaving like the same and throws an error.

    When I have all the information, then trainee section validated == "Approved" or else one of the options in the option set. The workflow triggers when this field changes. So I believe when I change to something else apart from "Approved", it is throwing me an error irrespective of moving of next stage. ? 

    Screenshot of Workflow.

    pastedimage1564969092774v1.png

    pastedimage1564969150829v2.png

    pastedimage1564969191408v3.png

  • Suggested answer
    RaviKashyap Profile Picture
    55,410 Moderator on at

    That is not correct.  The workflow needs to be trigger by the stage change and not when the field change. This is why it is triggering when you are saving the record.

    If you look at the link I shared initialy, they talk about creating a vworkflow which triggers on demand and then you select that workflow within the BPF.

    www.magnetismsolutions.com/.../how-to-run-workflow-on-business-process-flow-stage-change-in-dynamics-365

  • Poornimaa Profile Picture
    108 on at

    This feature is available only on Dynamics 365 business process flow(Adding workflow within BPF) and not on CRM 2016. We are using CRM 2016.

  • Verified answer
    gdas Profile Picture
    50,091 Moderator on at

    You can try with JS code -

    function onLoad() {

    Xrm.Page.data.process.addOnStageChange(getStage);

    }

    function getStage() {

    var activeStage = Xrm.Page.data.process.getActiveStage();

    var stageId = activeStage.getId();

    var stageName = activeStage.getName();

    If (stageName=="stagename")

    {

    if (Check the optionset value )

    {

    // Set previous stage as active stage

    //Set form notification

    }

    }

    }

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans