2016年6月13日 星期一

CRM2011 Opportunity Alert Message on Close Won(Plugin)

CRM2011 Opportunity Alert Message on Close Won(Plugin)

PreWinOpportunity.cs

  1. if (context.InputParameters.Contains("OpportunityClose") && context.InputParameters["OpportunityClose"] is Entity)
  2.  
  3.             {
  4.  
  5.                 #region Throw Exception For Test
  6.  
  7.                 //throw new InvalidPluginExecutionException("PreWinOpportunity - OpportunityCloseWon");
  8.  
  9.                 #endregion
  10.  
  11.  
  12.  
  13.                 var entity = (Entity)context.InputParameters["OpportunityClose"];
  14.  
  15.  
  16.  
  17.                 if (entity.Attributes.Contains("opportunityid"))
  18.  
  19.                 {
  20.  
  21.                     var opportunityId = ((EntityReference)entity.Attributes["opportunityid"]).Id;
  22.  
  23.  
  24.  
  25.                     var serviceFactory =
  26.  
  27.                     (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
  28.  
  29.  
  30.  
  31.                     // Getting the service from the Organisation Service.
  32.  
  33.                     IOrganizationService crmService = serviceFactory.CreateOrganizationService(context.UserId);
  34.  
  35.  
  36.  
  37.                     Entity opportunity = crmService.Retrieve("opportunity", opportunityId, new ColumnSet(new string[] { "description" }));
  38.  
  39.                     if (!opportunity.Contains("description"))
  40.  
  41.                     {
  42.  
  43.                         throw new InvalidPluginExecutionException("You must provide a value for description.");
  44.  
  45.                     }
  46.  
  47.                     else
  48.  
  49.                     {
  50.  
  51.                         //throw new InvalidPluginExecutionException("none");
  52.  
  53.                     }
  54.  
  55.                 }
  56.  
  57.                 else
  58.  
  59.                 {
  60.  
  61.                     throw new InvalidPluginExecutionException("none:opportunityid");
  62.  
  63.                 }
  64.  
  65.             }
  66.  
  67.             else
  68.  
  69.             {
  70.  
  71.                 throw new InvalidPluginExecutionException("none:PreWinOpportunity - OpportunityCloseWon");
  72.  
  73.             }
  74.  
  75.         }


PluginRegistration.exe



沒有留言:

張貼留言