Wednesday, December 17, 2008

Close Opportunity via SDK

To close a CRM opportunity is different comparing to other CRM entities. If you want to close an opportunity, you need to use the WinOpportunityRequest and LostOpportunityRequest in the CRM SDK instead of the SetState requests. The code snippet below simply shows you how to set an opportunity to Win status via the CRM SDK.

opportunityclose close = new opportunityclose();
close.opportunityid = new Lookup();
close.opportunityid.Value = targetOppId;

WinOpportunityRequest request = new WinOpportunityRequest();
request.OpportunityClose = close;
// Update the status code according to your environment
request.Status = 1;


1 comment:

Chris Alleaume said...

Thanks, Darren, for this.
Been searching high and low through various posts and articles and kept hitting my head.

You can try setting the status = -1 for the system default for losing or winning an opportunity (my 2 cents worth).