针对报价产品的Dynamic CRM 2013预操作插件未执行

时间:2014-12-11 16:19:38

标签: dynamics-crm dynamics-crm-2013

EDIT。

问题解决了。我在名称中创建了没有下划线的新项目。因此,在未注册的旧程序集和注册的新程序集之后,执行插件。同样在新项目中,我使用没有密码的密钥签署了dll。有助于神秘的消失。谢谢大家的时间。

=============================================== ===========================

插件的上下文是:销售部门正在创建报价并将产品添加到报价中。引号中有一列LineItemNumber。因此,当人们想要将产品移动到3个位置时,它只是将LineItemNumber更改为3(示例来自8)。所以,插件正在重写LineItemNumbers。所以,3转到4,4 => 5等等。 这是插件代码:

using System;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;

namespace plugin_fix_line_item_number
{
    public class FixLineItemNumbers : IPlugin
    {
        public void Execute(IServiceProvider serviceProvider)
        {
            // Obtain the execution context from the service provider.
            IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

            // Get a reference to the Organization service.
            IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
            IOrganizationService service = factory.CreateOrganizationService(context.UserId);

            if (context.InputParameters != null)
            {

                //Get Target - includes everything changed
                Entity entity = (Entity)context.InputParameters["Target"];

                //Get Pre Image
                Entity image = context.PreEntityImages["PreImage"];

                // post image
                //Entity imagePost = context.PostEntityImages["PostImage"];

                int? new_lin = null; //lineitemnumber
                int? old_lin = null;

                if (entity.Attributes.Contains("lineitemnumber"))
                {
                    new_lin = (int)entity.Attributes["lineitemnumber"];
                    old_lin = (int)image.Attributes["lineitemnumber"];

                    if (new_lin < 1) return; 

                    if (new_lin != null && old_lin != null)
                    {
                        if (new_lin != old_lin)
                        {
                            bool pieskaitiit = true; //by default, count lineItemNumber up
                            EntityCollection products = new EntityCollection();
                            QueryExpression q = new QueryExpression("quotedetail");
                            q.ColumnSet = new ColumnSet(new string[] { "lineitemnumber" });
                            q.Criteria.FilterOperator = LogicalOperator.And;

                            Guid quote_id = ((EntityReference)image.Attributes["quoteid"]).Id;

                            q.Criteria.AddCondition("quoteid", ConditionOperator.Equal, quote_id);
                            if (new_lin > old_lin) // 2 pozīcija pārtop par 5    2 => 5
                            {
                                q.Criteria.AddCondition("lineitemnumber", ConditionOperator.LessEqual, new_lin);
                                q.Criteria.AddCondition("lineitemnumber", ConditionOperator.GreaterThan, old_lin);
                                pieskaitiit = false; // here must count down
                            }
                            else{ // 5 pozīcija pārvietojas uz otro    5 => 2
                                q.Criteria.AddCondition("lineitemnumber",ConditionOperator.LessThan, old_lin);
                                q.Criteria.AddCondition("lineitemnumber",ConditionOperator.LessThan, old_lin);
                            }
                            products = service.RetrieveMultiple(q);
                            foreach(Entity e in products.Entities)
                            {
                                int lin = e.GetAttributeValue<int>("lineitemnumber");
                                if (pieskaitiit) lin++; else lin--;
                                e.Attributes["lineitemnumber"] = 9;
                                service.Update(e);
                            }

                        }
                    }
                }
            }
        }//
    }
}

我已经注册了插件,它看到了插件所需的所有变量。我禁用了插件步骤ActivityFeeds.Plugins.ActivityClose: Update of any Entity,因为如果它已启用,当我保存quoteProducts表单时,我收到错误:

Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: An error occurred. Contact a system administrator or refer to the Microsoft Dynamics CRM SDK troubleshooting guide.Detail: 
<OrganizationServiceFault xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/xrm/2011/Contracts">
  <ErrorCode>-2147220891</ErrorCode>
  <ErrorDetails xmlns:d2p1="http://schemas.datacontract.org/2004/07/System.Collections.Generic">
    <KeyValuePairOfstringanyType>
      <d2p1:key>OperationStatus</d2p1:key>
      <d2p1:value xmlns:d4p1="http://www.w3.org/2001/XMLSchema" i:type="d4p1:string">0</d2p1:value>
    </KeyValuePairOfstringanyType>
    <KeyValuePairOfstringanyType>
      <d2p1:key>SubErrorCode</d2p1:key>
      <d2p1:value xmlns:d4p1="http://www.w3.org/2001/XMLSchema" i:type="d4p1:string">-2146233088</d2p1:value>
    </KeyValuePairOfstringanyType>
  </ErrorDetails>
  <Message>An error occurred. Contact a system administrator or refer to the Microsoft Dynamics CRM SDK troubleshooting guide.</Message>
  <Timestamp>2014-12-11T15:38:01.0167124Z</Timestamp>
  <InnerFault i:nil="true" />
  <TraceText>

[ActivityFeeds.Plugins: ActivityFeeds.Plugins.ActivityClose]
[6213e0c9-2881-e411-9ac4-0050569aa6cf: ActivityFeeds.Plugins.ActivityClose: Update of  any Entity]


</TraceText>
</OrganizationServiceFault>

我搜索谷歌并发现:https://community.dynamics.com/crm/f/117/p/90521/170686.aspx 因此,如果我禁用ActivityFeeds.Plugins.ActivityClose步骤,那么在保存表单时,不会对数据库进行任何更改(通过插件)。即使我在第一个之前添加行throw new Exception("Mega error");,也没有任何反应,Form保存数据但插件未执行。

我也尝试了插件分析器(http://inogic.com/blog/2012/06/how-to-debug-plugins-using-profiler/)。我跑得很好。如果禁用ActivityFeeds.Plugins.ActivityClose步骤,然后运行探查器然后调试,则抛出异常。

这个插件只有一个,执行前操作。

我还能研究什么?一些系统配置问题?也许有人有一些想法我还可以尝试。感谢。

1 个答案:

答案 0 :(得分:0)

问题解决了。我在名称中创建了没有下划线的新C#项目。因此,在未注册的旧程序集和在crm中注册的新程序集之后,将执行插件。同样在新项目中,我使用没有密码的密钥签署了dll。有助于神秘的消失。同样ActivityFeeds.Plugins.ActivityClose: Update of any Entity我离开了。 谢谢大家的时间。