Dynamics Crm online 2016设置机会状态代码

时间:2016-09-21 14:57:31

标签: dynamics-crm-2016

我正在寻找将机会的状态代码设置为“不活动”或“关闭”所需的C#(控制台应用程序)语法。实际上我也想知道在哪里可以找到statecode的可用值,因为在字段属性中我看到数据类型是“Status”,但是我看不到可用的值。

提前谢谢

2 个答案:

答案 0 :(得分:4)

机会的有效州代码:

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

因为您希望“关闭”商机,请使用LoseOpportunityRequest SDK消息“取消”商机。

答案 1 :(得分:2)

您需要使用LoseOpportunityRequest来更改状态。还有一个WonOpportunityRequest。作为更改为已关闭丢失状态的一部分,您需要创建opportunityclose实体,该实体是LoseOpportunityRequest处理的一部分。

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);

归功于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