简体   繁体   English

如何设置机会状态-Dynamics CRM?

[英]How to set the Opportunity Status - Dynamics CRM?

I'm trying to update the status of open opportunity by using the WinOpportunityRequest & LoseOpportunityRequest API provided in the MSDN. 我正在尝试使用MSDN中提供的WinOpportunityRequest和LoseOpportunityRequest API更新开放机会的状态。 I've followed the code which was given in the MSDN & I even referred to stackoverflow's Set Opportunity Status 我遵循了MSDN中给出的代码,甚至提到了stackoverflow的“ 设置机会状态”

But, When I run this following code for the open opportunity it throws error stating that 但是,当我为公开机会运行以下代码时,会引发错误,指出

LoseOpportunityRequest req = new LoseOpportunityRequest();
Entity opportunityClose = new Entity("opportunityclose");
opportunityClose.Attributes.Add("opportunityid", new EntityReference(OptyEntityName, new Guid("xxxx-xxx")));
opportunityClose.Attributes.Add("subject", "Lost the Opportunity!");
req.OpportunityClose = opportunityClose;
// 4 = Cancelled and 5 = Out-Sold
req.Status = new OptionSetValue(4);
LoseOpportunityResponse resp = (LoseOpportunityResponse)_serviceProxy.Execute(req);

Error - 错误-

4 is not a valid status code on opportunity with Id(Guid) Id(Guid)上的机会不是有效的状态码4

When I tried to change the status of the closed opportunity it says that opportunity is already closed . 当我尝试更改已关闭机会的状态时,它表示该机会已经关闭

One more thing to consider is this status in my CRM has a padlock icon that means it is locked. 需要考虑的另一件事是,我的CRM中的此状态带有一个挂锁图标,表示它已被锁定。

So is it possible to change the status or not and is it based on the role? 那么是否可以更改状态,是否基于角色?

For an open opportunity, we can change the status to either win or lose. 对于开放的机会,我们可以将状态更改为赢或输。 So we will use the WinOpportunityRequest and LoseOpportunityRequest in here . 因此,我们将在此处使用WinOpportunityRequestLoseOpportunityRequest

So, we need to change the value to -1 so that CRM can load the default status code. 因此,我们需要将值更改为-1,以便CRM可以加载默认状态代码。

req.Status = new OptionSetValue(4);

after changing to -1 it doesn't throw any exception. 更改为-1后,不会引发任何异常。

req.Status = new OptionSetValue(-1);

once the execute call is performed. 一旦执行了执行调用。 The opportunity value will be changed to lost. 机会价值将变为丢失。 The opportunity will be closed. 机会将被关闭。

To re-open the closed opportunity, we can use the SetStateRequest class . 要重新打开已关闭的机会,我们可以使用SetStateRequest类 The code would be as follows. 代码如下。

                var stateRef = new EntityReference("optyname", new Guid("optyid"));
                SetStateRequest req = new SetStateRequest();
                req.State = new OptionSetValue(0);
                req.Status = new OptionSetValue(2);
                req.EntityMoniker = stateRef;
                SetStateResponse stateSet = (SetStateResponse)_serviceProxy.Execute(req);

After the execute call is performed the opportunity status is set back to open and the status is displayed as open. 执行执行调用后,机会状态将重新设置为打开,并且状态显示为打开。

state code is different from status. 状态码与状态不同。 state code can have open, win or close. 状态代码可以具有打开,赢得或关闭状态。 status can have multiple values. 状态可以有多个值。 detailed info is provide at msdn . 详细信息在msdn中提供。

You are right. 你是对的。 State & Status are conjoined twins. 状态和状态是双胞胎。 You cannot update only one of them, always go in pair. 您不能仅更新其中之一,请始终配对。

在此处输入图片说明

State = StateCode 状态= StateCode
Status Reason = StatusCode (field with Padlock) 状态原因= StatusCode(带有挂锁的字段)

More read 阅读更多

In your answer code, this is framed correctly in SetStateRequest req. 在您的答案代码中,这在SetStateRequest req中正确构建。

req.State = new OptionSetValue(0);
req.Status = new OptionSetValue(2);

But in OP, you set only Status not State. 但是在OP中,仅设置状态而不是状态。

Per MSDN , LoseOpportunityRequest with OpportunityClose entity has to close it without issues when you pass only Status. 根据MSDN ,仅通过状态时,带有OpportunityClose实体的LoseOpportunityRequest必须关闭它而没有问题。 But you are not alone . 但是你并不孤单

Ref: Opportunity & OpportunityClose 参考: 机会机会关闭

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 动态CRM CRM创建报价没有机会 - dynamics crm api create quote without opportunity 当潜在客户合格时,如何防止Dynamics CRM 2015创造机会? - How to prevent Dynamics CRM 2015 from creating an opportunity when a lead is qualified? 无法使用估算的关闭日期对Dynamics CRM“机会”交易类型执行过滤 - Not able to perform Filter on Dynamics CRM “Opportunity” transaction type with estimatedclosedate 如何在Dynamics CRM中设置条件属性名称是否布尔 - How to set if condition attribute Name bool in Dynamics CRM 如何序列化 Dynamics CRM 元数据 - How to serialize Dynamics CRM metadata Microsoft CRM:如何通过代码重新打开机会? 不推荐使用SetStateRequest,更新不起作用 - Microsoft CRM: How to reopen an opportunity by code? SetStateRequest deprecated, Update not working 如何使用C#Web API关闭CRM机会实体 - How to close CRM opportunity entity using C# web api 如何在Dynamics CRM 2016中的插件预操作中设置发票ID? - How to set Invoice ID in plugin pre-operation in Dynamics CRM 2016? 如何使用C#在MS Dynamics CRM中为案例的自定义字段设置/获取值 - how to set/get value to the custom field of a case in MS Dynamics CRM using C# Linq与Dynamics CRM,如何处理null? 你调用的对象是空的 - Linq with Dynamics CRM, how to handle null ? Object reference not set to an instance of an object
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM