Dynamics CRM如何带上实体记录的当前Id

Dynamics CRM how to bring the current Id of a entity record

我是社区的新人,我正在使用一个表单插件,我需要在其中获取该表单的所有值,为了实现这一点,我创建了一个 preOperation 更新插件。只有当我修改该表单内的字段时,我的插件才能完美运行。但是,普通用户(我是管理员)不能修改表单的任何值。 我读到我可以使用方法

service.Retrieve(string entityName, Guid id, ColumnSet columnSet);

我的问题是如何获取当前记录的Guid id? 很抱歉,如果这很明显,但我是 Dynamics CRM 的新手,非常感谢您能给我的任何帮助。

由于您的插件是在预操作级别注册的,因此该记录还没有写入数据库。

您将必须使用已注册的预实体图像来访问属性(表单值)。

var pluginExecutionContext = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
var entity = pluginExecutionContext.PreEntityImages["ImageName"]; //the name that you have registered your image with
//iterate through all the attributes 
foreach (var attribute in entity.Attributes)
{
  //access the attribute values
  var attributeValue = attribute.Value;  
}

如果您不想使用实体的 pre/post 图片,您可以按照您在问题中提到的那样检索记录。如果您的插件已在更新消息上注册,则获取当前记录的 ID 很容易。

Entity entity = (Entity)context.InputParameters["Target"];
Guid recordID = entity.Id;

也看看这个

https://community.dynamics.com/crm/b/crminogic/archive/2010/07/26/pre-image-38-post-image-explained-33