字典中不存在给定的键
我正在尝试为 MS Dynamics CRM 4.0 制作一个简单的插件,其中在订单更新时以 SOAP 消息发送销售订单的数据。 奇怪的是,每次我尝试保存/(执行插件)时都会收到此错误。 因此,当我更新销售订单(任何字段)然后保存时,我收到错误:
字典中不存在给定的键。
当我之后立即再次保存时(甚至没有更改两次保存之间的任何内容),它会正确执行并为我提供我想要的所有数据。实际上每次都是同样的事情:第一次保存:错误,第二次保存:正确执行。
有什么想法吗?
这是我的代码的第一部分;在这种情况下,它实际上获取销售订单的数据集:
public class CompleteOrderPlugin : IPlugin
{
public void Execute(IPluginExecutionContext context)
{
DynamicEntity entity = null;
if (context.InputParameters.Properties.Contains(ParameterName.Target) &&
context.InputParameters.Properties[ParameterName.Target] is DynamicEntity)
{
entity = (DynamicEntity)context.InputParameters[ParameterName.Target];
if (entity.Name != EntityName.salesorder.ToString()) { return; }
}
else
{
return;
}
剩下的就是我使用属性中的值来填充我自己的变量。
I am trying to make a simple plugin for MS Dynamics CRM 4.0 where send data of a salesorder in a SOAP message on the update of the order.
The strange thing is that I get this error every other time i try to save /(execute the plugin).
So when I update (any field) of a salesorder and then save I get the error:
The given key was not present in the dictionary.
When I save again right away after that(without even changing anything in between the two saves) it executes correctly and gives me all data I want. It is really every time the same thing: first save: error, second save: execute correctly.
Any ideas what this could be?
This is the first part of my code; where it actually gets the dataset of the salesorder in this case:
public class CompleteOrderPlugin : IPlugin
{
public void Execute(IPluginExecutionContext context)
{
DynamicEntity entity = null;
if (context.InputParameters.Properties.Contains(ParameterName.Target) &&
context.InputParameters.Properties[ParameterName.Target] is DynamicEntity)
{
entity = (DynamicEntity)context.InputParameters[ParameterName.Target];
if (entity.Name != EntityName.salesorder.ToString()) { return; }
}
else
{
return;
}
The rest is where I use values from attributes to fill my own variables.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我通过首先在插件注册工具中制作销售订单的发布图像,然后使用发布图像中的值而不是直接来自销售订单的值来解决此问题。我这样做是因为在更新时您只能获得实际更改的值。
I fixed this by first making a Post Image of the salesorder in the plugin regsitration tool and then using the values in the Post Image instead of the ones comming directly from the salesorder. This I did because on a update you get only the values that actually changed.