来自相关实体的插件更新字段
Plugin update field from a related entity
我想构建一个插件来更新相关实体的字段。
在实体协议上,我有两个字段:字段 A(查找帐户)和字段 B(查找联系人)
我必须检查客户(字段 A)中的选项集字段是否是一个特定值,然后更新联系人(字段 B)中的选项集字段。
就是这样。谢谢!
Entity agreement = (Entity)context.InputParameters["Target"]; // this is your target entity from which plugin is firing.
// Now do whatever your check you wish to perform
// once you are ready to update lookupAccount Record below code will work
Entity lookupAccount = new Entity();
lookupAccount.LogicalName = "account";
lookupAccount.Id = agreement.GetAttributeValue<EntityReference>("field A").Id;
lookupAccount["optionSetFieldToUpdate"]= new OptionSetValue(1234);
orgService.Update(lookupAccount);
// In similar way you can perform update for ook-up Contact)
Entity lookupContact = new Entity();
lookupContact.LogicalName = "contact";
lookupContact.Id = agreement.GetAttributeValue<EntityReference>("field B").Id;
lookupContact["optionSetFieldToUpdate"]= new OptionSetValue(1234);
orgService.Update(lookupContact);
我想构建一个插件来更新相关实体的字段。 在实体协议上,我有两个字段:字段 A(查找帐户)和字段 B(查找联系人)
我必须检查客户(字段 A)中的选项集字段是否是一个特定值,然后更新联系人(字段 B)中的选项集字段。
就是这样。谢谢!
Entity agreement = (Entity)context.InputParameters["Target"]; // this is your target entity from which plugin is firing.
// Now do whatever your check you wish to perform
// once you are ready to update lookupAccount Record below code will work
Entity lookupAccount = new Entity();
lookupAccount.LogicalName = "account";
lookupAccount.Id = agreement.GetAttributeValue<EntityReference>("field A").Id;
lookupAccount["optionSetFieldToUpdate"]= new OptionSetValue(1234);
orgService.Update(lookupAccount);
// In similar way you can perform update for ook-up Contact)
Entity lookupContact = new Entity();
lookupContact.LogicalName = "contact";
lookupContact.Id = agreement.GetAttributeValue<EntityReference>("field B").Id;
lookupContact["optionSetFieldToUpdate"]= new OptionSetValue(1234);
orgService.Update(lookupContact);