in

Paul Rausch

Close an Opportunity in CRM 3.0 via web services

It took me a little time to figure out how set the state/status of a Opportunity to a win.  Other times I've had to set states/status on a CRM object I've only had to use the corresponding SetStateRequest object which does exist for Opportunity but fails to do what I needed.  The following code shows how to close an Opportunity.  I apologize its in VB.

CRMService is the web reference to the CRM service URL.

Dim oppClose As CRMService.opportunityclose = New CRMService.opportunityclose
oppClose.opportunityid =
New CRMService.Lookup
oppClose.opportunityid.type = CRMService.EntityName.opportunity.ToString()
oppClose.opportunityid.Value = opportunity.opportunityid.Value

'Set fields related to the win
oppClose.actualrevenue = CrmTypes.CreateCrmMoney(0)
oppClose.actualend = CrmTypes.CreateCrmDateTime(DateTime.Today.ToShortDateString())

Dim woReq As CRMService.WinOpportunityRequest = New CRMService.WinOpportunityRequest
woReq.OpportunityClose = oppClose
woReq.Status = 3

Dim service As CRMService.CrmService = CrmServiceManager.GetService() 'Custom service reference factory
Dim woResp As CRMService.WinOpportunityResponse = CType(service.Execute(close), CRMService.WinOpportunityResponse)

Only published comments... Apr 02 2008, 10:02 AM by prausch
Filed under: ,

Leave a Comment

(required)  
(optional)
(required)  
Add
Inetium, LLC. Disclaimer