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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested Answer

Add conditional approval to Opportunity Step

(0) ShareShare
ReportReport
Posted on by 3,317
Hi 
I want to add conditional approval where email goes out to a bunch of people if a opportunity product lines total sum exceed a certain amount, and this is should pervent from creating quote or saving quote if cannot hid ethe + button to create quote. What is teh best way to add a conditional approval step where it only triigers the approval for osme opportunities? and idealy email goes out where approver can either approve from teh email or access line to opportunity and approve step , and originator shoudl see who approved. Quote part can be handled separtely from plugin. please suggest pro code if thats better or low code best as i know how to craete plugins
Categories:
I have the same question (0)
  • Assisted by AI
    Saif Ali Sabri Profile Picture
    2,654 Moderator on at
    To implement conditional approval on the Opportunity entity with restrictions on Quote creation, you can approach this in two ways depending on whether you prefer low-code (Power Automate + Approvals) or pro-code (custom plugin/workflow):

    Low-code approach (Power Automate + Approvals)

    1. Create a Power Automate flow triggered on update of Opportunity or on Quote creation attempt.
    2. Condition check: Sum the Opportunity Product Line totals.
      • If the total exceeds your threshold, trigger the Approval process.
    3. Approval action:
      • Use the Approvals connector to send an email to approvers.
      • Approvers can approve directly from the email or via the Approvals app.
      • Store the approval response back in the Opportunity record.
    4. Restrict Quote creation:
      • Add a Business Rule or JavaScript on the Opportunity form to disable/hide the “+ Quote” button until approval status = Approved.
      • Alternatively, use Dataverse security role logic to block saving until approval is complete.
    5. Visibility:
      • Add a field on Opportunity to show “Approved By” and populate it from the approval response.

    Pro-code approach (Plugin + Custom Table)

    1. Plugin on Quote Create/Save event:
      • Calculate the Opportunity Product Line total.
      • If it exceeds the threshold and approval is not yet granted, throw an exception to block Quote creation.
    2. Approval tracking:
      • Create a custom table (e.g., OpportunityApproval) linked to Opportunity.
      • Store approver, status, and timestamp.
    3. Email notification:
      • Use a custom workflow activity or plugin to send emails with approval links.
      • Approvers can click the link to update the approval record.
    4. Originator visibility:
      • Show the approval status and approver details on the Opportunity form.
    5. Quote handling:
      • Once approval is granted, the plugin allows Quote creation.

    Recommendation

    • If you are comfortable with plugins, the pro-code approach gives you more control over blocking Quote creation.
    • If you prefer low-code, Power Automate with Approvals is faster to set up and integrates well with email-based approvals.
    • Since you mentioned you already know how to create plugins, you can combine both: use plugin for Quote restriction and Power Automate for email approvals.

      This way, you achieve:
       

    • Conditional approval only for Opportunities exceeding the threshold.
    • Email-based approval with direct response.
    • Visibility of approver details for the originator.
    • Controlled Quote creation via plugin logic.
  • Assisted by AI
    Saif Ali Sabri Profile Picture
    2,654 Moderator on at
    Here’s a plugin code skeleton you can adapt for enforcing conditional approval on Quote creation in Dynamics 365:

    Plugin Skeleton
     

    using System;
    using Microsoft.Xrm.Sdk;
    using Microsoft.Xrm.Sdk.Query;
    namespace OpportunityApprovalPlugin
    {
        public class QuoteCreateValidation : IPlugin
        {
            public void Execute(IServiceProvider serviceProvider)
            {
                // Obtain execution context
                IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
                IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
                IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
                // Ensure target is Quote entity
                if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
                {
                    Entity quote = (Entity)context.InputParameters["Target"];
                    // Get related Opportunity
                    if (quote.Contains("opportunityid"))
                    {
                        EntityReference oppRef = (EntityReference)quote["opportunityid"];
                        Guid oppId = oppRef.Id;
                        // Retrieve Opportunity Product Lines
                        QueryExpression query = new QueryExpression("opportunityproduct");
                        query.ColumnSet = new ColumnSet("extendedamount");
                        query.Criteria.AddCondition("opportunityid", ConditionOperator.Equal, oppId);
                        EntityCollection oppProducts = service.RetrieveMultiple(query);
                        // Calculate total
                        decimal totalAmount = 0;
                        foreach (Entity product in oppProducts.Entities)
                        {
                            if (product.Contains("extendedamount"))
                            {
                                Money amount = (Money)product["extendedamount"];
                                totalAmount += amount.Value;
                            }
                        }
                        // Retrieve approval status from Opportunity
                        Entity opportunity = service.Retrieve("opportunity", oppId, new ColumnSet("new_approvalstatus"));
                        string approvalStatus = opportunity.Contains("new_approvalstatus") ? opportunity["new_approvalstatus"].ToString() : "Pending";
                        // Check condition
                        decimal threshold = 50000; // Example threshold
                        if (totalAmount >= threshold && approvalStatus != "Approved")
                        {
                            throw new InvalidPluginExecutionException("Quote creation blocked. Approval required for Opportunity total exceeding threshold.");
                        }
                    }
                }
            }
        }
    }

    Key Points

    • Trigger: Register this plugin on Pre-Create of Quote.
    • Logic:
      • Retrieve Opportunity Product Lines.
      • Sum the extendedamount.
      • Compare against threshold.
      • Check custom field new_approvalstatus on Opportunity.
    • Block: If threshold exceeded and not approved → throw exception.
    • Approval Integration:
      • Approval status can be updated via Power Automate flow or another plugin when approver responds.
      • Store approver details in custom fields (ApprovedBy, ApprovalDate).
    This skeleton enforces server-side validation, ensuring no Quote can be created until approval is granted. Combine it with the Power Automate flow for email-based approvals to complete the solution.
  • Suggested answer
    11manish Profile Picture
    842 on at
    For a Dynamics 365 Sales solution, I would recommend a hybrid approach that combines Power Automate for approvals and a plugin for enforcement.

    Use Power Automate for the approval workflow, email notifications, Teams approvals, and audit updates, and use a Dynamics 365 plugin to enforce the business
     
    rule that prevents quote creation until approval is completed.

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Hamza H Profile Picture

Hamza H 140 Super User 2026 Season 1

#2
Nagaraju_Matta Profile Picture

Nagaraju_Matta 128

#3
Abhilash Warrier Profile Picture

Abhilash Warrier 70 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans