我正在开发一个用c#编写的插件,用于动态crm 2016 update 1的在线实例。
如标题中所述,我需要从填写“至”字段的“电话呼叫”实体中检索联系信息。那是不适合我的代码
angular
.module('demo', [])
.controller('DefaultController', DefaultController);
function DefaultController() {
var vm = this;
vm.Teközel = 'Hello, World!';
}
问题是#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
为空,即使我确定CRM上的字段正在填充数据。
我在post和pre中试过了插件,但它没有任何工作。
activityParty.ActivityId.Id
有人知道如何解决这个问题吗?
编辑:
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,是否有任何建议?
答案 0 :(得分:2)
尝试替换
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();