Dynamics Crm online 2016 set opportunity statecode

随声附和 提交于 2019-12-24 08:24:37

问题


I am looking for the C# (console application) syntax required to set the statecode of an opportunity to "not active" or "closed". In fact I would also like to know where I can find the available values for statecode, since in the field properties I see that the datatype is "Status", but I don't see the available values.

Thank you in advance


回答1:


Valid state codes for Opportunity:

statecode        -   statuscode 
0 (Open)         -   1 (In Progress), 2 (On Hold)
1 (Won)          -   3 (Won)
2 (Lost)         -   4 (Cancelled), 5 (Out-Sold)

Because you want to "Close" the opportunity, use LoseOpportunityRequest SDK message to "Cancel" the opportunity.




回答2:


You need to use the LoseOpportunityRequest to change the status. There is also a WonOpportunityRequest. As part of the changing to a closed-lost status you need to create an opportunityclose entity, which is part of the LoseOpportunityRequest processing.

LoseOpportunityRequest req = new LoseOpportunityRequest();

Entity opportunityClose = new Entity("opportunityclose");
opportunityClose.Attributes.Add("opportunityid", new EntityReference("opportunity", new Guid("D711C1BD-23DA-E011-94B4-1CC1DEF177C2")));
opportunityClose.Attributes.Add("subject", "Lost the Opportunity!");
req.OpportunityClose = opportunityClose;
// 4 = Cancelled and 5 = Out-Sold
req.Status = new OptionSetValue(4);
LoseOpportunityResponse resp = (LoseOpportunityResponse)_orgService.Execute(req);

Credit to https://community.dynamics.com/crm/b/mileyja/archive/2011/09/08/close-an-opportunity-as-lost-using-net-or-jscript-in-microsoft-dynamics-crm-2011-with-loseopportunityrequest



来源:https://stackoverflow.com/questions/39620048/dynamics-crm-online-2016-set-opportunity-statecode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!