Thursday 14 April 2016

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

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

public static void CloseOpportunityAsLose(IOrganizationService crmService, Guid guidOpportunityId)
{
      LoseOpportunityRequest req = new LoseOpportunityRequest();
      Entity opportunityClose = new Entity("opportunityclose");
      opportunityClose.Attributes.Add("opportunityid", new EntityReference("opportunity", guidOpportunityId));
      opportunityClose.Attributes.Add("subject", "Lost the Opportunity!");
      req.OpportunityClose = opportunityClose;
      OptionSetValue osvLostValue = new OptionSetValue();
      osvLostValue.Value = 4;
      req.Status = osvLostValue;
      LoseOpportunityResponse resp = (LoseOpportunityResponse)crmService.Execute(req);
}

Hope this helps.
 
--
Happy CRM'ing

Gopinath

 

No comments:

Post a Comment