更新消息后期操作中的PostEntityImages根本没有密钥

时间:2014-02-27 13:34:39

标签: dynamics-crm-2011

我已经通过Visual Studio中的CRM工具为某个实体的更新消息注册了一个插件(在后期操作中),并且还注册了该插件的后映像,如下所示:

enter image description here

enter image description here

这是我的代码:

  

protected void ExecutePostOpportunityUpdate(LocalPluginContext   localContext)           {

        if (localContext == null)
        {
            throw new ArgumentNullException("localContext");
        }




        // TODO: Implement your custom Plug-in business logic.
        IPluginExecutionContext context = localContext.PluginExecutionContext;

        Entity postImage = (Entity)context.PostEntityImages["PostImage"];
     

...

     

}

但它会抛出一个错误,并说PostEntityImages根本没有关键。我调试了插件,发现根本就没有密钥。

请你帮帮我吗?

1 个答案:

答案 0 :(得分:1)

看看你的代码,你必须检索机会的实际实体:试试这个

 try
 {

Entity postOpportunityService = (Entity)context.PostEntityImages["PostImage"];

// Opportunity service's parent opportunity lookup reference
EntityReference opportunityReference = (EntityReference)postOpportunityService.Attributes["mpc_opportunityid"];

// Columns to be retrieved for opportunity (aka. columns to be edited)
ColumnSet opportunityColumnSet = new ColumnSet(new string[] { "estimatedvalue", "mpc_estoneoffinvoicing", "mpc_estinvoicingperyear" });

// Retrieve actual opportunity entity
Entity opportunity = service.Retrieve(opportunityReference.LogicalName, opportunityReference.Id, opportunityColumnSet);             

}

catch (FaultException<OrganizationServiceFault> ex) {   tracingService.Trace("FaultException", ex.ToString()); }