Thursday, 14 April 2016

Close Opportunity as Won in CRM 2011/2013/2015/2016

Hi,
 
Here is the code to close an Opportunity as Won using the MS Dynamics CRM SDK.
 
In this example, I am using WinOpportunityRequest to close an Opportunity as Won.

public static void CloseOpportunityAsWon(IOrganizationService crmService, Guid guidOpportunityId)
{
       WinOpportunityRequest req = new WinOpportunityRequest();
       Entity opportunityClose = new Entity("opportunityclose");
       opportunityClose.Attributes.Add("opportunityid", new EntityReference("opportunity", guidOpportunityId));
       opportunityClose.Attributes.Add("subject", "Won the Opportunity!");
       req.OpportunityClose = opportunityClose;
       OptionSetValue osvWon = new OptionSetValue();
       osvWon.Value = 3;
       req.Status = osvWon;
       WinOpportunityResponse resp = (WinOpportunityResponse)crmService.Execute(req);
}

Hope this helps.
 
--
Happy CRM'ing

Gopinath

 

No comments:

Post a Comment