我无法使用以下代码在插件上检索"two option"字段的选定值
bool? update = entity.GetAttributeValue<bool?>("new_updatecontacts");
bool update = entity.GetAttributeValue<bool>("new_updatecontacts");
if (update)
{
..................
}
是否有其他方法检索相同的?我已经发布了同样的问题,但没有得到明确的答案,所以我再问一遍。
默认情况下,插件只包含已添加/更新的字段的值。对于其他事件,你有其他属性但我们现在就用这个。
所以如果你想确保你有一个值,你需要跑去CRM获取一个副本。
var context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
var serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
var service = serviceFactory.CreateOrganizationService(context.InitiatingUserId);
var target = context.InputParameters["Target"] as Entity;
if (!target.Contains("new_updatecontacts"))
{
target = service.Retrieve(target.LogicalName, target.Id, new ColumnSet(new [] { "new_updatecontacts", "other_required_fields_here" });
}
//now you know it is present
值得先检查它是否在那里,因为它节省了服务器的点击。