Skip to main content

Notifications

Customer experience | Sales, Customer Insights,...
Answered

GenerateQuoteFromOpportunityRequest from plugin

Posted on by

I am facing an issue with GenerateQuoteFromOpportunityRequest,

I have created an action that calls a new plugin the only thing this plugin does is call generate a quote from an opportunity using GenerateQuoteFromOpportunityRequest, the issue is when an opportunity contains only 300 items the process takes more then 2min which intern causes the plugin the fail....

Is there a better way to do this from a plugin?

 

using System;
using System.Linq;
using System.Text;
using Microsoft.Xrm.Sdk;
using System.Net;
using Microsoft.Xrm.Sdk.Query;
using System.IO;
using System.Runtime.Serialization.Json;
using System.Collections.Generic;
using Microsoft.Xrm.Sdk.Messages;
using System.ServiceModel;
using Microsoft.Crm.Sdk.Messages;

namespace ex_Dynamics365_Plugins
{
    public class exRecordCreateOrDeletePlugin : IPlugin
    {
        public void Execute(IServiceProvider serviceProvider)
        {
            // Get tracing service for debugging purposes
            ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));

            //tracingService.Trace("exRecordCreateOrDeletePlugin - called");
            // Get the context of the message
            IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
            IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
            IOrganizationService dynamicsService = serviceFactory.CreateOrganizationService(context.UserId);
            tracingService.Trace("exRecordCreateOrDeletePlugin - called");
            
            Entity opportunity = new Entity();
            if (context.InputParameters.Contains("opportunity")) {
                opportunity = (Entity)context.InputParameters["opportunity"];
            }

            tracingService.Trace("exRecordCreateOrDeletePlugin - paramaters set");
			
			if (context.MessageName.Equals("ex_CreateQuoteAction")) {
                Entity new_quote;

                tracingService.Trace("ex_CreateQuoteAction - GenerateQuoteFromOpportunityRequest");
                GenerateQuoteFromOpportunityRequest req = new GenerateQuoteFromOpportunityRequest();
                req.OpportunityId = opportunity.Id;
                req.ColumnSet = new ColumnSet(true);
                tracingService.Trace("ex_CreateQuoteAction - Execute GenerateQuoteFromOpportunityRequest");

                GenerateQuoteFromOpportunityResponse resp = ((GenerateQuoteFromOpportunityResponse)dynamicsService.Execute(req));
                tracingService.Trace("ex_CreateQuoteAction - define new new_quote based on the response");

                new_quote = resp.Entity;
                new_quote["totalamount"] = 0;
                dynamicsService.Update(new_quote);
            }
            else
            {
                tracingService.Trace("exRecordCreateOrDeletePlugin - no action specified");
            }

        }
    }
}

  • Abdul Wahab Profile Picture
    Abdul Wahab 12,070 Super User 2024 Season 1 on at
    RE: GenerateQuoteFromOpportunityRequest from plugin

    Hi RynaCRM,

    It will be done but needs some Research and Development.


    Thanks
    Regards,
    Abdul Wahab
    Power Platform/Customer Engagement Developer/Lead/Solution Architecture/Project Manager
    Direct/WhatsApp:+923323281237
    E-mail: abdulwahabubit@outlook.com
    Skype: abdul.wahabubit

  • RyanCRM Profile Picture
    RyanCRM on at
    RE: GenerateQuoteFromOpportunityRequest from plugin

    i dont suppose you have an example of how i could trigger this using the webapi ? / or if it is possible to do this?

  • Verified answer
    Abdul Wahab Profile Picture
    Abdul Wahab 12,070 Super User 2024 Season 1 on at
    RE: GenerateQuoteFromOpportunityRequest from plugin

    Hi RyanCRM,

    This is not possible using a plugin/custom workflow extension. You need to power automate or call some other service...

    Let me know if I can provide you with more details.

    Thanks
    Regards,
    Abdul Wahab
    Power Platform/Customer Engagement Developer/Lead/Solution Architecture/Project Manager
    Direct/WhatsApp:+923323281237
    E-mail: abdulwahabubit@outlook.com
    Skype: abdul.wahabubit

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,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans