【问题标题】:Get related entity statecode value to use as a check获取相关实体状态码值以用作检查
【发布时间】:2015-04-27 20:43:59
【问题描述】:

我需要能够仅在相关机会具有statecode1 的条件下执行我的代码

在我的代码中,我可以使用 Microsoft Dynamics SDK 提供的 GenerateSalesOrderFromOpportunityRequest 类在创建机会关闭活动时创建新的销售订单。

这种方法的缺点是,当机会以赢得(1) 或丢失(2) 关闭时,系统会创建opportunityclose 活动。此外,opportunityclose 活动中没有属性表明它是赢还是输。因此,找出它的唯一方法是从相关机会中获取该属性。

在我的代码中,我能够从相关机会中获取其他属性,例如 name,但除了 0 之外,我无法获得 statecode 的任何其他值。

这是我的代码:

Entity postImageEntity = (context.PostEntityImages != null && context.PostEntityImages.Contains(this.postImageAlias)) ? context.PostEntityImages[this.postImageAlias] : null;

            if (postImageEntity.LogicalName == "opportunityclose" && postImageEntity.Attributes.Contains("opportunityid") && postImageEntity.Attributes["opportunityid"] != null)
            {
                // Create an entity reference for the related opportunity to get the id for the GenerateSalesOrderFromOpportunityRequest class
                EntityReference entityRef = (EntityReference)postImageEntity.Attributes["opportunityid"];

                // Retrieve the opportunity that the closed opportunity activity was created for.
                Entity RelatedEntityRef = service.Retrieve("opportunity", entityRef.Id, new ColumnSet( new String[] {"statecode","statuscode", "name"}));

                OptionSetValue StateCode = (OptionSetValue)RelatedEntityRef.Attributes["statecode"];

                OptionSetValue StatusCode = (OptionSetValue)RelatedEntityRef.Attributes["statuscode"];

                string OppName = (string)RelatedEntityRef.Attributes["name"];

                if (entityRef.LogicalName == "opportunity" && StateCode.Value == 1)
                {
                    try
                    {
                        GenerateSalesOrderFromOpportunityRequest req = new GenerateSalesOrderFromOpportunityRequest();
                        req.OpportunityId = entityRef.Id;
                        req.ColumnSet = new ColumnSet(true);
                        GenerateSalesOrderFromOpportunityResponse resp = (GenerateSalesOrderFromOpportunityResponse)service.Execute(req);
                    }
                    catch (FaultException ex)
                    {
                        throw new InvalidPluginExecutionException("An error occurred in the plug-in.", ex);
                    }
                }
            }

回顾:为此,我只需要能够获得与opportunityclose 相关的opportunity 的实际statecode 值。目前我只能得到0,即使我知道机会的状态代码是1

其他信息:

  • 这适用于 Microsoft Dynamics Online 2013/2015(两者都适用)
  • 使用 SKD v6.1.1
  • 插件有效,但无论机会是赢还是输都会触发。 (无意)

【问题讨论】:

    标签: c# plugins entity dynamics-crm dynamics-crm-2013


    【解决方案1】:

    您不能查看机会以查看状态是赢还是输。我

    如果需要,您可以检索 OpportunityClose 并更改状态 https://msdn.microsoft.com/en-us/library/gg334301.aspx

    我假设它将机会设置为接近 1,因为您正在执行 GenerateSalesOrderFromOpportunityRequest,只有在您赢得机会时才会这样做(例如,您不会推进失去的机会)。

    【讨论】:

    • 我最初尝试在机会的Win 消息上执行插件,但是当使用该消息时,它不会让您使用postentityimage 来获取机会 id 的 id。所以我在有效的opportuntiyclose 活动上运行它。但是,当我尝试获取statecode(status) 的机会以查看它是赢还是输时,我每次都会得到0。在上面的代码中,这是我用来获取状态代码的。这看起来不对吗? OptionSetValue StateCode = (OptionSetValue)RelatedEntityRef.Attributes["statecode"];
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-05-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多