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 :
Customer experience | Sales, Customer Insights,...
Answered

Opportunity Sales Stage and prevent from moving to next stage...

(3) ShareShare
ReportReport
Posted on by 217
Hello,
 
I am trying to stop users from going on from the fist stage in an opportunity record unless the 4 fields have the value of Yes.  If any of the 4 fields are set to No, and user clicks next stage button, it should throw a message saying all fields must say Yes before moving to next stage.
 
Then if the fields are all yes in the first stage, user can click next stage and then before they can move on from the next stage, same thing, all fields there need to be Yes.
 
 
How can I do this?
I have the same question (0)
  • Verified answer
    Nitesh Raj Profile Picture
    188 on at

    There are four methods to enforce this validation:

    1️⃣ Business Process Flow (BPF) Mandatory Fields (No Code – Best Practice)
    2️⃣ Plugin (C# – Server-Side Enforcement)
    3️⃣ JavaScript (OnSave Event – Client-Side Enforcement)
    4️⃣ Business Rules (No Code – UI Enforcement)

     

    Approach 1: Business Process Flow (BPF) Mandatory Fields (No Code – Best Practice)

    Best for simple enforcement without coding.

    Steps to Implement:

    - Navigate to PowerApps > Business Process Flows (BPF).
    - Open the Opportunity BPF and locate the first stage ("Qualify").
    - Add the four required fields to the stage and mark them as mandatory.
    - Save and Publish the BPF.

    🔸 Limitations:

     Users must set the fields to "Yes" before moving to the next stage, but they can later change them to "No".
     Does not enforce validation dynamically after the stage transition.
     

     

    Approach 2: Plugin (C# – Server-Side Enforcement)

    Best for strict enforcement at the database level.

    How It Works:

    • Triggers on stage change.
    • Checks if all four fields are set to "Yes".
    • If not, throws an error message preventing progression.

    C# Plugin Code Sample:

    ---
     
    public class ValidateOpportunityStage : IPlugin
    {
        public void Execute(IServiceProvider serviceProvider)
        {
            IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
            if (context.MessageName != "Update" || !context.InputParameters.Contains("Target"))
                return;
            Entity entity = (Entity)context.InputParameters["Target"];
            if (entity.LogicalName != "opportunity")
                return;
            // Retrieve field values
            bool field1 = entity.Contains("new_field1") && (bool)entity["new_field1"];
            bool field2 = entity.Contains("new_field2") && (bool)entity["new_field2"];
            bool field3 = entity.Contains("new_field3") && (bool)entity["new_field3"];
            bool field4 = entity.Contains("new_field4") && (bool)entity["new_field4"];
            // Prevent stage change if any field is "No"
            if (!field1 || !field2 || !field3 || !field4)
            {
                throw new InvalidPluginExecutionException("All fields must be 'Yes' before moving to the next stage.");
            }
        }
    }
     
    ---
     

    Steps to Implement:

    - Register the plugin using the Plugin Registration Tool.
    - Attach it to the On Stage Change event of the Opportunity entity.

    🔸 Limitations:

    - Requires development effort.
    - Enforces validation only when the record is saved.

     

     

    Approach 3: JavaScript (OnSave Event – Client-Side Enforcement)

    Best for real-time validation before saving.

    How It Works:

    - Checks the Sales Stage field before saving.
    - If the stage is not "Qualify", verifies that all four fields are "Yes".
    - If any field is "No", prevents saving and displays an alert.
     
    JavaScript Code Sample (OnSave Event):
     
    ---
     
    function validateFieldsOnSave(executionContext) {
        var formContext = executionContext.getFormContext();
        
        // Get the Sales Stage field (Update with your actual field name)
        var salesStage = formContext.getAttribute("sales_stage").getValue(); 
        
        // Define the first stage value (update based on your system's values)
        var firstStageValue = "Qualify"; 
        // Only run validation if the stage is NOT the first stage
        if (salesStage !== firstStageValue) {
            var field1 = formContext.getAttribute("new_field1").getValue();
            var field2 = formContext.getAttribute("new_field2").getValue();
            var field3 = formContext.getAttribute("new_field3").getValue();
            var field4 = formContext.getAttribute("new_field4").getValue();
            // Check if all fields are "Yes" (true)
            if (field1 !== true || field2 !== true || field3 !== true || field4 !== true) {
                // Prevent form save
                executionContext.getEventArgs().preventDefault();
                alert("All fields must be 'Yes' before moving to the next stage.");
            }
        }
    }
     
    ---
     
    🔸 Steps to Implement:
    - Upload the script as a JavaScript Web Resource in CRM.
    - Open the Opportunity Form, go to Form Properties.
    - Attach the script to the OnSave event.
    - Save & Publish the form.
     
    🔸 Limitations:
     Users can still bypass by modifying fields after stage transition.
     

    Approach 4: Business Rules (No Code – UI Enforcement)

    Best for making fields mandatory dynamically.

    How It Works:
    - Tracks the Sales Stage field.
    - If the stage is not "Qualify", makes the four fields mandatory.
    - This ensures users must update these fields before saving.

    🔸 Steps to Implement Business Rule:
    - Go to PowerApps > Opportunity Entity > Business Rules.
    - Click New Business Rule and add these conditions:
     
    - If Sales Stage ≠ "Qualify", then:
         Set Field 1 → Mandatory
         Set Field 2 → Mandatory
         Set Field 3 → Mandatory
         Set Field 4 → Mandatory
    - Save & Activate the rule.

    🔸 Limitations:
    -  Works only in UI forms, not in back-end/API updates.

     
    I hope you will find your answer from these approaches. 

    If this helps you, please consider approving this answer. 

    Regards,
    Nitesh Raj
     
  • Verified answer
    Daivat Vartak (v-9davar) Profile Picture
    7,841 Moderator on at
    Hello CU31101219-0,
     
    You can achieve this in Dynamics 365 using a combination of Business Rules and Real-time Workflows (or Power Automate Flows).
     
    Here's a breakdown of the process:
    1. Business Rules (Client-Side Validation):
    • Purpose: To provide immediate, client-side validation to prevent users from moving to the next stage if the required fields are not set to "Yes."
    • Steps:
      1. Create Business Rules for Each Stage:
        • Navigate to Settings > Customizations > Customize the System.
        • Expand Entities > Opportunity > Business Rules.
        • Create a new Business Rule for each stage where you need this validation.
      2. Add Conditions:
        • For each Business Rule, add a condition that checks if any of the four "Yes/No" fields are equal to "No."
      3. Add Show Error Message Action:
        • If the condition is true (any field is "No"), add a "Show Error Message" action.
        • Set the error message to something like: "All fields must be set to 'Yes' before moving to the next stage."
        • Specify the field where the error message should appear (you can choose one of the "Yes/No" fields).
      4. Scope:
        • Set the scope of the Business Rule to "Entity" to ensure it applies to all users.
      5. Activate:
        • Activate the Business Rule.
    2. Real-time Workflows (Server-Side Validation) or Power Automate Flows:
    • Purpose: To provide server-side validation that prevents the stage transition if the required fields are not set to "Yes." This is important because Business Rules can sometimes be bypassed.
    • Real-time Workflows (Classic):
      1. Create Real-time Workflow:
        • Navigate to Settings > Processes.
        • Create a new process for the Opportunity entity.
        • Set the category to "Workflow."
        • Set the type to "Real-time workflow."
        • Check the "Record status changes" option.
        • Select the "Before" option.
      2. Add Condition:
        • Add a condition that checks if the "Stage Category" (or the specific stage field) has changed.
        • Add a second condition that checks if any of the four "Yes/No" fields are equal to "No."
      3. Add Stop Workflow with Status of Canceled:
        • If both conditions are true, add a "Stop Workflow with Status of Canceled" step.
        • Set the status message to something like: "All fields must be set to 'Yes' before moving to the next stage."
        • This will prevent the stage transition.
      4. Activate:
        • Activate the workflow.
    • Power Automate Flows (Modern):
      1. Create Automated Cloud Flow:
        • Create an automated cloud flow that is triggered when an Opportunity record is updated.
      2. Add Condition:
        • Add a condition that checks if the "Stage Category" (or the specific stage field) has changed.
        • Add a second condition that checks if any of the four "Yes/No" fields are equal to "No."
      3. Add Terminate Action:
        • If both conditions are true, add a "Terminate" action.
        • Set the status to "Cancelled."
        • Set the message to something like: "All fields must be set to 'Yes' before moving to the next stage."
      4. Save and Turn On:
        • Save and turn on the flow.
     
    Important Notes:
    • Field Schema Names: Make sure you use the correct schema names for your "Yes/No" fields and the stage field in both the Business Rules and the workflow/flow.
    • Error Messages: Provide clear and informative error messages to guide users.
    • Testing: Thoroughly test your Business Rules and workflows/flows in a development environment before deploying them to production.
    • User Experience: Consider the user experience when implementing these validations. Make sure they are not overly restrictive or confusing.
    • Stage Category vs. Specific Stage Field: Depending on how your stages are configured, you might need to use the "Stage Category" or the specific stage field in your conditions.
    • Real-time workflows are considered classic and are being phased out, Power Automate Flows are the modern way to do this.
     
    If my answer was helpful, please click Like, and if it solved your problem, please mark it as verified to help other community members find more.
    If you have further questions, please feel free to contact me.
     
    My response was crafted with AI assistance and tailored to provide detailed and actionable guidance for your Microsoft Dynamics 365 query.
     
    Regards,
    Daivat Vartak

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 March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
ManoVerse Profile Picture

ManoVerse 184 Super User 2026 Season 1

#2
11manish Profile Picture

11manish 125

#3
CU11031447-0 Profile Picture

CU11031447-0 100

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans