You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

C#插件获取目标实体属性值为空问题求助

问题排查与解决方案

核心原因

Dynamics 365插件在更新(Update)操作触发时,InputParameters["Target"]仅包含本次表单提交中被修改的字段,而非目标实体的全量属性。如果触发插件的字段不是new_name,那么Target里不会包含这个属性,调用GetAttributeValue<string>("new_name")自然返回空值——哪怕表单里该字段有有效值。

解决方法

要获取目标实体的完整属性值,需要通过IOrganizationService主动从系统中检索全量实体:

修改后的代码示例:

public void Execute(IServiceProvider serviceProvider)
{
    ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
    IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
    IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
    IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);

    Entity entityTarget = context.InputParameters["Target"] as Entity;
    Guid guid = entityTarget.Id;
    
    // 检索完整的目标实体,指定需要的属性(或用"*"获取所有属性)
    Entity fullEntity = service.Retrieve(entityTarget.LogicalName, guid, new ColumnSet("new_name"));
    string entityName = fullEntity.GetAttributeValue<string>("new_name");
    
    tracingService.Trace("entityName = " + entityName);
}

额外说明

  • 如果插件是在Create操作触发,Target会包含所有提交的字段,但Update操作仅包含修改字段是Dynamics 365的默认行为。
  • 也可以在插件注册时,将new_name添加到筛选字段列表中,但这仅适用于new_name本身被修改的场景——如果是其他字段变更触发插件,这个方法无效。

内容的提问来源于stack exchange,提问作者AMD

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.02 06:00:47