Plugins 字典中不存在给定的键
我正在crm 5.0中开发一个插件,从一个名为“ct\U marketvalue”的实体中检索日期“ct\U valuedate”,并格式化并保存在名为“ct\U dateserial”的字段中 调试“字典中不存在给定的密钥”时出错Plugins 字典中不存在给定的键,plugins,dynamics-crm,crm,Plugins,Dynamics Crm,Crm,我正在crm 5.0中开发一个插件,从一个名为“ct\U marketvalue”的实体中检索日期“ct\U valuedate”,并格式化并保存在名为“ct\U dateserial”的字段中 调试“字典中不存在给定的密钥”时出错 }关于代码的几点注释 您应该在代码中检查context.PostEntityImages是否包含“ct\uMarketValue”。有可能忘记注册或在图像名称中出错 使用.ToEntity可能比使用.attributes[“ct\u valuedate”]访问属性更
}关于代码的几点注释
@Paramosh感谢您的输入。Create没有前映像,我必须使用postentity映像。我更改了代码。我仍然收到相同的错误。我对交换机外壳内的所有代码进行了注释。我收到了相同的错误。
public class MarketValueDateFormatting : PluginBase
{
protected override void ExecutePlugin()
{
try
{
switch (_crmMessage)
{
case CrmPluginMessageEnum.Create:
if (_context.InputParameters.Contains("ct_marketvalue"))
{
//Obtain the logical name of the entity
string moniker1 = ((EntityReference)_context.InputParameters["EntityMoniker"]).LogicalName;
//Verify that the target entity represents an Account.
//If not, this plug-in was not registered correctly.
if (moniker1.Equals("ct_marketvalue"))
{
Entity marketvalueimage = (Entity)_context.PostEntityImages["ct_marketvalue"];
Guid marketvalueid = marketvalueimage.Id;
if (marketvalueimage.Contains("ct_valuedate"))
{
DateTime dateserial = (DateTime)marketvalueimage.Attributes["ct_valuedate"];
String dateserialstring = dateserial.ToString("YYYYMMdd");
Ct_marketvalue marketvalue = new Ct_marketvalue();
marketvalue.Ct_dateserial = dateserialstring;
marketvalue.Id = marketvalueid;
_serviceContext.UpdateObject(marketvalue);
}
}
}
break;
}
catch (Exception ex)
{
throw ex;
}
}
}