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 voidCloseOpportunityAsWon(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

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s