From a user at one of my customers:
CRM not cooperating.
Hmm, not exactly sure how to respond to that.
I am sure that there is another blog that has posted code like this before, but I was cleaning up a project this morning, saw these two methods, and decided to just post them here so I could find them later. :)
These are in C#. For more information on how they work, please review the CRM SDK.
private void CloseOpportunity(Guid opportunityId, int statusCode, string description) { opportunityclose oppclose = new opportunityclose(); oppclose.opportunityid = new Lookup(); oppclose.opportunityid.type = EntityName.opportunity.ToString(); oppclose.opportunityid.Value = opportunityId; oppclose.description = description; oppclose.actualend = new CrmDateTime(DateTime.Now.ToString()); WinOpportunityRequest woReq = new WinOpportunityRequest(); woReq.OpportunityClose = oppclose; woReq.Status = 3; // Won; crmService.Execute(woReq); } private void CancelOpportunity(Guid opportunityId, int statusCode, string description) { opportunityclose oppclose = new opportunityclose(); oppclose.opportunityid = new Lookup(); oppclose.opportunityid.type = EntityName.opportunity.ToString(); oppclose.opportunityid.Value = opportunityId; oppclose.description = description; oppclose.actualend = new CrmDateTime(DateTime.Now.ToString()); LoseOpportunityRequest woReq = new LoseOpportunityRequest(); woReq.OpportunityClose = oppclose; woReq.Status = statusCode; crmService.Execute(woReq); }





