Dynamics crm 业务流程错误:Dynamics CRM和Visual Studio
我已经为基于多个字段的父记录的后期更新编写了一个C插件。 在本文中,我试图根据子实体中更新的值计算父实体中的总值,子实体中有rate和units字段。所以基本上,总数=速率*单位。代码构建良好,但在dynamics crm中创建新表单时,它会生成一个业务流程错误:来自插件的意外异常执行:Parentchild1.parentchildpluginSystem.Collections.Generic.KeyNotFoundException:字典中不存在给定的键 这是我的密码: 命名空间Parentchild1 { 公共类parentchildplugin:IPlugin { 私人实体主管/母公司Dynamics crm 业务流程错误:Dynamics CRM和Visual Studio,dynamics-crm,Dynamics Crm,我已经为基于多个字段的父记录的后期更新编写了一个C插件。 在本文中,我试图根据子实体中更新的值计算父实体中的总值,子实体中有rate和units字段。所以基本上,总数=速率*单位。代码构建良好,但在dynamics crm中创建新表单时,它会生成一个业务流程错误:来自插件的意外异常执行:Parentchild1.parentchildpluginSystem.Collections.Generic.KeyNotFoundException:字典中不存在给定的键 这是我的密码: 命名空间Paren
public void Execute(IServiceProvider serviceProvider)
{
// Obtain the execution context from the service provider.
IPluginExecutionContext context =
(IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
// Get a reference to the Organization service.
IOrganizationServiceFactory factory =
(IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = factory.CreateOrganizationService(context.UserId);
if (context.InputParameters != null)
{
//entity = (Entity)context.InputParameters["Target"];
//Instead of getting entity from Target, we use the Image
Entity entity = context.PostEntityImages["PostImage"];
Money rate = (Money)entity.Attributes["abcevent_rate"];
int unit = (int)entity.Attributes["abcevent_unit"];
// EntityReference parent = (EntityReference)entity.Attributes["abcevent_parentid"];
//Multiply
// Money total = new Money(rate.Value * units);
//Set the update entity
Entity parententity = new Entity("abcevent_parent");
//parententity.Id = parent.Id;
//parententity.Attributes["abcevent_total"] = total;
// abcevent_parentid = Guid IOrganizationservice.Create(Entity parentid);
Guid parentGuid = service.Create(abcevent_parent);
EntityReference parent = (EntityReference)entity.Attributes["abcevent_parentid"];
Money total = new Money(rate.Value * unit);
//Update
//service.Update(parententity);
}
您提出的问题: 字典中不存在给定的键 这是因为列表中没有一个键,如果您尝试获取如下属性 int number=intentity.Attributes[随机属性] 这会抛出错误,因为它不在上下文中 您必须确保属性在上下文中…最佳做法是请求包含: 如果entity.Containsrandom_属性 这样您就知道可以安全地访问该属性
另一个原因可能是图像,请确保它在上下文中。此外,请确保PostImage的Post Image名称与Post Image在插件注册工具中的注册方式相匹配。尝试了此操作。现在出现无效参数异常。为parententity创建GUID时生成的错误异常将仅包含attri但是这已经改变了。我建议在postmage中包含abcevent_parentid,并从那里开始。你可以用你的实际代码更新你的帖子吗?我看到很多东西被评论了,所以我们可以更好地帮助你。