Plugins Microsoft Dynamics CRM 2013 SDK问题-错误

Plugins Microsoft Dynamics CRM 2013 SDK问题-错误,plugins,crm,microsoft-dynamics,Plugins,Crm,Microsoft Dynamics,我在Microsoft dynamics crm 2013中遇到以下问题: [Contracts.Plugins: Contracts.Plugins.Autonumber] [97f9577d-1394-e311-a461-000c29f9727b: PostInvoiceDetailsUpdate] Execption: Object reference not set to an instance of an object. at Contracts.Plugins.SumAmoun

我在Microsoft dynamics crm 2013中遇到以下问题:

[Contracts.Plugins: Contracts.Plugins.Autonumber]
[97f9577d-1394-e311-a461-000c29f9727b: PostInvoiceDetailsUpdate]
Execption: Object reference not set to an instance of an object.    at Contracts.Plugins.SumAmounts.Execute(IServiceProvider serviceProvider)
Execption: An error occured in the plug-in.    at Contracts.Plugins.SumAmounts.Execute(IServiceProvider serviceProvider)
at Contracts.Plugins.Autonumber.Execute(IServiceProvider serviceProvider)
我有两个母公司(法律合同或协议),在1:M的关系中引用修订和财务细节。我需要对子记录中的金额求和,并将该金额存储在父记录中

[Contracts.Plugins: Contracts.Plugins.Autonumber]
[97f9577d-1394-e311-a461-000c29f9727b: PostInvoiceDetailsUpdate]
Execption: Object reference not set to an instance of an object.    at Contracts.Plugins.SumAmounts.Execute(IServiceProvider serviceProvider)
Execption: An error occured in the plug-in.    at Contracts.Plugins.SumAmounts.Execute(IServiceProvider serviceProvider)
at Contracts.Plugins.Autonumber.Execute(IServiceProvider serviceProvider)
我编写了一个插件,可以为每个子实体创建、更新和删除

[Contracts.Plugins: Contracts.Plugins.Autonumber]
[97f9577d-1394-e311-a461-000c29f9727b: PostInvoiceDetailsUpdate]
Execption: Object reference not set to an instance of an object.    at Contracts.Plugins.SumAmounts.Execute(IServiceProvider serviceProvider)
Execption: An error occured in the plug-in.    at Contracts.Plugins.SumAmounts.Execute(IServiceProvider serviceProvider)
at Contracts.Plugins.Autonumber.Execute(IServiceProvider serviceProvider)
必须采取的措施如下:

[Contracts.Plugins: Contracts.Plugins.Autonumber]
[97f9577d-1394-e311-a461-000c29f9727b: PostInvoiceDetailsUpdate]
Execption: Object reference not set to an instance of an object.    at Contracts.Plugins.SumAmounts.Execute(IServiceProvider serviceProvider)
Execption: An error occured in the plug-in.    at Contracts.Plugins.SumAmounts.Execute(IServiceProvider serviceProvider)
at Contracts.Plugins.Autonumber.Execute(IServiceProvider serviceProvider)
  • 看看我的父母是合法合同还是协议
  • 将所有子记录金额相加
  • 找到父项并存储求和值
  • 问题: Microsoft已在新SDK中删除了从子网格组件获取信息的功能,因此即使客户端有可用的数据,也无法访问

    [Contracts.Plugins: Contracts.Plugins.Autonumber]
    [97f9577d-1394-e311-a461-000c29f9727b: PostInvoiceDetailsUpdate]
    Execption: Object reference not set to an instance of an object.    at Contracts.Plugins.SumAmounts.Execute(IServiceProvider serviceProvider)
    Execption: An error occured in the plug-in.    at Contracts.Plugins.SumAmounts.Execute(IServiceProvider serviceProvider)
    at Contracts.Plugins.Autonumber.Execute(IServiceProvider serviceProvider)
    
    当我运行下面的代码时,我在parentID上得到一个null的异常:“If(c.Attributes.Contains(…)”测试导致一个异常

    [Contracts.Plugins: Contracts.Plugins.Autonumber]
    [97f9577d-1394-e311-a461-000c29f9727b: PostInvoiceDetailsUpdate]
    Execption: Object reference not set to an instance of an object.    at Contracts.Plugins.SumAmounts.Execute(IServiceProvider serviceProvider)
    Execption: An error occured in the plug-in.    at Contracts.Plugins.SumAmounts.Execute(IServiceProvider serviceProvider)
    at Contracts.Plugins.Autonumber.Execute(IServiceProvider serviceProvider)
    
    如果我运行与命令行相同的代码,它就可以正常工作,只有当作为插件运行时,它才会呕吐

    [Contracts.Plugins: Contracts.Plugins.Autonumber]
    [97f9577d-1394-e311-a461-000c29f9727b: PostInvoiceDetailsUpdate]
    Execption: Object reference not set to an instance of an object.    at Contracts.Plugins.SumAmounts.Execute(IServiceProvider serviceProvider)
    Execption: An error occured in the plug-in.    at Contracts.Plugins.SumAmounts.Execute(IServiceProvider serviceProvider)
    at Contracts.Plugins.Autonumber.Execute(IServiceProvider serviceProvider)
    
    代码段:

             EntityReference parentAgreementId = new EntityReference();
             EntityReference parentContractId = new EntityReference();
             QueryByAttribute querybyattribute = new QueryByAttribute("new_invoicedetails");
                     querybyattribute.ColumnSet = new ColumnSet(true);
    
                     //  Attribute to query.
    
                    querybyattribute.Attributes.AddRange("new_invoicedetailsid");
    
                     //  Value of queried attribute to return.
    
                    querybyattribute.Values.AddRange(sItem.getChildId());
    
                     //  Query passed to service proxy.
                     EntityCollection retrieved = service.RetrieveMultiple(querybyattribute);
    
                     //  Iterate through returned collection.
                     foreach (var c in retrieved.Entities)
                     {
                         If (c.Attributes.Contains("new_contractnumberid"))
                         {
                             parentContractId = c.GetAttributeValue<EntityReference>("new_contractnumberid");
                         }
    
                         If (c.Attributes.Contains("new_agreementnumberid"))
                         {
                             parentAgreementId = c.GetAttributeValue<EntityReference>("new_agreementnumberid");
                         }
    
    [Contracts.Plugins: Contracts.Plugins.Autonumber]
    [97f9577d-1394-e311-a461-000c29f9727b: PostInvoiceDetailsUpdate]
    Execption: Object reference not set to an instance of an object.    at Contracts.Plugins.SumAmounts.Execute(IServiceProvider serviceProvider)
    Execption: An error occured in the plug-in.    at Contracts.Plugins.SumAmounts.Execute(IServiceProvider serviceProvider)
    at Contracts.Plugins.Autonumber.Execute(IServiceProvider serviceProvider)
    

    我认为If应该写成If(小写)。我错了吗?

    小写的“If语句”不影响结果。你有什么例外?你能在这里发布吗?
    [Contracts.Plugins: Contracts.Plugins.Autonumber]
    [97f9577d-1394-e311-a461-000c29f9727b: PostInvoiceDetailsUpdate]
    Execption: Object reference not set to an instance of an object.    at Contracts.Plugins.SumAmounts.Execute(IServiceProvider serviceProvider)
    Execption: An error occured in the plug-in.    at Contracts.Plugins.SumAmounts.Execute(IServiceProvider serviceProvider)
    at Contracts.Plugins.Autonumber.Execute(IServiceProvider serviceProvider)