本文介绍了如何设置机会状态-Dynamics CRM?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过 WinOpportunityRequest& ;;更新状态打开机会。 MSDN中提供了LoseOpportunityRequest API。
我遵循了MSDN&我什至提到了stackoverflow的

I'm trying to update the status of open opportunity by using the WinOpportunityRequest & LoseOpportunityRequest API provided in the MSDN.I've followed the code which was given in the MSDN & I even referred to stackoverflow's Set Opportunity Status

但是,当我为开放机会运行以下代码时,会抛出错误,指出

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

错误-

当我尝试更改封闭的机会,它表示机会已经封闭

When I tried to change the status of the closed opportunity it says that opportunity is already closed.

需要考虑的另一件事是我的CRM中的这种状态

One more thing to consider is this status in my CRM has a padlock icon that means it is locked.

那么是否可以更改状态,它是否基于角色?

So is it possible to change the status or not and is it based on the role?

推荐答案

对于开放的机会,我们可以将状态更改为赢或输。因此,我们将使用WinOpportunityRequest 和 LoseOpportunityRequest 。 messages.loseopportunityrequest.aspx#Examples rel = nofollow noreferrer>此处。

For an open opportunity, we can change the status to either win or lose. So we will use the WinOpportunityRequest and LoseOpportunityRequest in here.

因此,我们需要将值更改为-1,以便CRM可以加载默认状态代码。

So, we need to change the value to -1 so that CRM can load the default status code.

req.Status = new OptionSetValue(4);

更改为-1后,不会引发任何异常。

after changing to -1 it doesn't throw any exception.

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. 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.

这篇关于如何设置机会状态-Dynamics CRM?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 13:14