Dynamics crm 2011 联机检索当前ID Crm

Dynamics crm 2011 联机检索当前ID Crm,dynamics-crm-2011,dynamics-crm,crm,dynamics-crm-online,Dynamics Crm 2011,Dynamics Crm,Crm,Dynamics Crm Online,我正在使用此代码在关闭事件时获取事件的当前id! 但是收到了这个错误: 插件执行时出现意外异常:fecharincident.Plugins.PostIncidenteClose:System.Collections.Generic.KeyNotFoundException:字典中不存在给定的密钥 我的一个伙伴使用完全相同的代码,正在开发他的crm! 来点帮助 显然,InputParameters集合没有目标键值。检查您正在使用的请求是否具有目标InputParameter Entity tit

我正在使用此代码在关闭事件时获取事件的当前id! 但是收到了这个错误:

插件执行时出现意外异常:fecharincident.Plugins.PostIncidenteClose:System.Collections.Generic.KeyNotFoundException:字典中不存在给定的密钥

我的一个伙伴使用完全相同的代码,正在开发他的crm!
来点帮助

显然,InputParameters集合没有目标键值。检查您正在使用的请求是否具有目标InputParameter

Entity title = new Entity();
title = service.Retrieve("incident",((Guid)((Entity)context.InputParameters["Target"]).Id), new ColumnSet("title"));

打赌您的目标不包含在InputParameters中,导致KeyNotFoundException-字典中不存在给定的键

您可以检查Daryl解释的目标,或者使用工作流中可用的上下文,就像这样

if (context.InputParameters.Contains("Target") &&
    context.InputParameters["Target"] is Entity)
{
    // Obtain the target entity from the input parameters.
    title = service.Retrieve("incident", ((Entity)context.InputParameters["Target"]).Id, new ColumnSet("title"));

我试过你的方法,也犯过同样的错误coming@Nevesito我也会检查你的插件注册和你的伙伴。看看你是否能发现任何差异。你确定是那条线出错了吗?你怎么知道的?
protected override void Execute(CodeActivityContext executionContext)
    {
        // Create the context
        var context = executionContext.GetExtension<IWorkflowContext>();
        var title = new Entity();
        //context.PrimaryEntityName - should hold string incident
        //context.PrimaryEntityId - should hold your guid
        title = service.Retrieve(context.PrimaryEntityName, context.PrimaryEntityId, new ColumnSet("title"));
    }