代码之家  ›  专栏  ›  技术社区  ›  Michele Ietri

创建时从电话呼叫实体中的partylist字段检索联系人信息

  •  0
  • Michele Ietri  · 技术社区  · 8 年前

    我正在为dynamics crm 2016更新1的在线实例编写一个用c#编写的插件。

    正如标题中所说,我需要从填充“to”字段创建的“phonecall”实体中检索联系人信息。这是对我不起作用的代码

    #region Plugin execution
            try
            {
                tracingService.Trace("AutocompletePhonecalls: Plugin start.");
                XrmServiceContext svcContext = new XrmServiceContext(service);
    
                EntityCollection to = entity.GetAttributeValue<EntityCollection>("to");
    
                for (int i = 0; i < to.Entities.Count; i++)
                {
                    ActivityParty activityParty = to[i].ToEntity<ActivityParty>();
                    Contact contact = (from c in svcContext.ContactSet where c.Id.Equals(activityParty.ActivityId.Id) select c).FirstOrDefault();
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message + "\n" + ex.InnerException.Message);
            }
            #endregion
    

    activityParty.ActivityId.Id 为空,即使我确信CRM上的字段中填充了数据。 我在post和pre中尝试了该插件,但它无论如何都不能工作。

    the error i got from CRM

    Object reference not set to an instance of an object.Detail: 
    <OrganizationServiceFault xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/xrm/2011/Contracts">
      <ErrorCode>-2147220956</ErrorCode>
      <ErrorDetails xmlns:d2p1="http://schemas.datacontract.org/2004/07/System.Collections.Generic" />
      <Message>Unexpected exception from plug-in (Execute): CGN.Plugins.AutocompletePhonecalls: System.Exception: Exception has been thrown by the target of an invocation.
    Object reference not set to an instance of an object.</Message>
      <Timestamp>2016-09-09T09:47:59.4457726Z</Timestamp>
      <InnerFault i:nil="true" />
      <TraceText>
    AutocompletePhonecalls: Plugin start.
    </TraceText>
    </OrganizationServiceFault>
    
    Server stack trace: 
       at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
       at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
       at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs)
       at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
       at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
    
    Exception rethrown at [0]: 
       at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
       at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
       at Microsoft.Crm.Sandbox.ISandboxHost.ExecuteAndReturnTraceInfo(SandboxCallInfo callInfo, SandboxPluginExecutionContext requestContext, Guid pluginAssemblyId, Int32 sourceHash, String assemblyName, Guid pluginTypeId, String pluginTypeName, String pluginConfiguration, String pluginSecureConfig, String assemblyContents, Boolean returnTraceInfo)
       at Microsoft.Crm.Sandbox.SandboxPlugin.Execute(SandboxClient client, SandboxCallTracker callTracker, IExecutionContext requestContext, String assemblyContents, Boolean returnTraceInfo)
       at Microsoft.Crm.Sandbox.SandboxCodeUnit.Execute(IExecutionContext context)
    

    有人知道怎么解决这个问题吗?

    编辑: 活动方活动Id Id 返回的Id与联系人中的任何Id都不匹配,有什么建议吗?

    1 回复  |  直到 8 年前
        1
  •  2
  •   Andrew Butenko    8 年前

    尝试更换管路

    Contact contact = (from c in svcContext.ContactSet where c.Id.Equals(activityParty.ActivityId.Id) select c).FirstOrDefault();
    

    Contact contact = (from c in svcContext.ContactSet where c.Id.Equals(activityParty.PartyId.Id) select c).FirstOrDefault();