【问题标题】:CRM 2011 Organization Service Update() Failed inside PluginCRM 2011 组织服务更新()在插件内失败
【发布时间】:2015-02-10 01:03:56
【问题描述】:

我在我的帐户插件中获得了这段代码,该代码以前可以使用,但现在一直存在这个有线问题。

它试图做的是,当帐户更新时,也更新主要联系人。

ColumnSet contactCols = new ColumnSet(new string[] { "firstname"});
Entity contact = orgService.Retrieve("contact", contactId, contactCols);
tracer.Trace("firstname is " + contact["firstname"]);

contact["firstname"] = DateTime.Now.ToString();
orgService.Update(contact);  

Retrieve() 有效,但 Update() 会抛出以下异常:

Unhandled Exception: 
Microsoft.Xrm.Sdk.InvalidPluginExecutionException: 
System.ServiceModel.FaultException`1[Microsoft.Xrm.Sdk.OrganizationServiceFault]: 
System.ServiceModel.FaultException`1[Microsoft.Xrm.Sdk.OrganizationServiceFault]: 
System.NullReferenceException: 
Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support: #BF42D86C (Fault Detail is equal to Microsoft.Xrm.Sdk.OrganizationServiceFault). (Fault Detail is equal to Microsoft.Xrm.Sdk.OrganizationServiceFault).
  at CRMSyncPlugin.SyncEntityClass.Execute(IServiceProvider serviceProvider)
  at Microsoft.Crm.Asynchronous.V5ProxyPlugin.Execute(IServiceProvider serviceProvider)
  at Microsoft.Crm.Asynchronous.EventOperation.InvokePlugin(AsyncExecutionContext context, IPlugin pluginInstance)

它说 NullReferenceException,我只是想不通什么是 null。

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

在尝试了@Nicknow 的建议后,仍然是同样的错误。 这是我从跟踪中得到的:

Retrieving Contact: 048f9564-81b4-e311-a27c-0026553e0f7c
Retrieved Contact
firstname is John

检索成功,只是更新失败。谢谢

【问题讨论】:

  • 首先,您确定联系人记录作为firstname 的值返回吗?如果没有,你会得到一个例外。 tracer.Trace("firstname is " + contact["firstname"]); 是否正在写入跟踪信息?你能发布所有的ErrorLog文件吗?您可以连接 Visual Studio 调试器并捕获异常吗?这会告诉你行和空引用。
  • 请显示您的异常的全文。您是否收到跟踪日志?
  • 嗨@Siddique Mahsud,上面是异常的全文,是的,我收到了跟踪日志,成功收到名字,只是更新失败。谢谢

标签: dynamics-crm-2011 crm


【解决方案1】:

我添加了一些额外的跟踪和空值检查,这应该可以工作:

tracer.trace("Retrieving Contact: {0}", contactId.ToString());
ColumnSet contactCols = new ColumnSet(new string[] { "firstname"});
Entity contact = orgService.Retrieve("contact", contactId, contactCols);
tracer.trace("Retrieved Contact");

tracer.Trace("firstname is " + contact.Attributes.Contains("firstname") ? contact["firstname"] : "(No Value for firstname)");

if (contact.Attributes.Contains("firstname")) contact["firstname"] = DateTime.Now.ToString();
else contact.Attributes.Add("firstname", DateTime.Now.ToString());
orgService.Update(contact);  

【讨论】:

  • 嗨 Nicknow,是的,名字返回得很好。我会试一试,让你知道。谢谢。
  • 嗨@Nicknow,仍然是同样的错误。这是我从跟踪中得到的: 检索联系人:048f9564-81b4-e311-a27c-0026553e0f7c 检索到的联系人名字是 John 只是更新失败。谢谢
【解决方案2】:

您可能会检查是否有另一个插件在联系人更新上运行 - 错误可能来自另一个插件而不是这个插件。

【讨论】:

    【解决方案3】:

    我通常不会尝试更新从 Retrieve 调用中获得的对象。只需新建一个联系人,设置 ID,并仅包含您要更改的字段。

    ColumnSet contactCols = new ColumnSet(new string[] { "firstname"});
    Entity contact = orgService.Retrieve("contact", contactId, contactCols);
    tracer.Trace("firstname is " + contact["firstname"]);
    var updateContact = new Contact();
    updateContact["contactId"] = contactId;
    updateContact["firstname"] = DateTime.Now.ToString();
    orgService.Update(updateContact); 
    

    我发现这往往可以避免这类问题。

    【讨论】:

      猜你喜欢
      • 2015-08-15
      • 2011-08-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-30
      • 1970-01-01
      • 1970-01-01
      • 2014-02-11
      相关资源
      最近更新 更多