locked
Getting Opportunity Close Description RRS feed

  • Question

  • Hi All, 

    How to get the Opportunity Close(as Won/as Lost) description and competitor from the opportunity Close Entity, on the closing of the Opportunity.

    Requirement:I need to get the description of the Opportunity close when we close the opportunity and send that text to some one

    Saturday, May 2, 2015 2:45 PM

Answers

  • You should be able to do this in a plugin registered on the Win and Lose messages of the opportunity entity. The OpportunityClose InputParameter (which is of type Entity) should give you the information you need

    Microsoft CRM MVP - http://mscrmuk.blogspot.com/ http://www.excitation.co.uk

    Saturday, May 2, 2015 5:57 PM
    Moderator
  • Hi All, 

    I found solution for this through java script by following below procedure on the change event of the status reason field.

    1.Fetching all the closed opportunities in descending order based on the Created on date from the Opportunity closed entity and taking the first record which is created newly in the Opportunity closed entity and putting description in the description field in the Opportunity.


    Tuesday, May 19, 2015 12:43 PM

All replies

  • You should be able to do this in a plugin registered on the Win and Lose messages of the opportunity entity. The OpportunityClose InputParameter (which is of type Entity) should give you the information you need

    Microsoft CRM MVP - http://mscrmuk.blogspot.com/ http://www.excitation.co.uk

    Saturday, May 2, 2015 5:57 PM
    Moderator
  • Here is the code to get description field. As David suggested, register the plugin on Win or/and Lose messages of opportunity entity.

        public class OpportunityLostWon : IPlugin
        {
            public void Execute(IServiceProvider ServiceProvider)
            {
                IPluginExecutionContext context = (IPluginExecutionContext)ServiceProvider.GetService(typeof(IPluginExecutionContext));
                IOrganizationService service = HelperClass.GetCRMService(ServiceProvider);
                      
                Entity OppClose = (Entity)context.InputParameters["OpportunityClose"];
    
                try
                 {
                        if (!OppClose.Contains("description"))
                        {
                            throw new InvalidPluginExecutionException("No Description Found");
                        }
                        else if (OppClose.Contains("description"))
                        {
                            string description = OppClose.GetAttributeValue<string>("description"); // Here you get your description
                            if ((description == string.Empty) || (description == null))
                            {
                                throw new InvalidPluginExecutionException("Description is Empty");
                            }
                        }
                 }
                catch (FaultException<OrganizationServiceFault> ex)
                  {
    
                        throw new InvalidPluginExecutionException("An error occurred in Opportunity  plug-in", ex);
                  }
            }
        }

    Hope this helps.

    H.Desai

    Thursday, May 7, 2015 10:17 PM
  • Hi All, 

    I found solution for this through java script by following below procedure on the change event of the status reason field.

    1.Fetching all the closed opportunities in descending order based on the Created on date from the Opportunity closed entity and taking the first record which is created newly in the Opportunity closed entity and putting description in the description field in the Opportunity.


    Tuesday, May 19, 2015 12:43 PM