【问题标题】:crm update prevalidation plugin can't get entitycrm 更新预验证插件无法获取实体
【发布时间】:2013-08-09 07:36:16
【问题描述】:

我有一个用于 crm 2011 的插件。使用 PreImage 进行更新预验证。我可以使用上下文很好地获得 PreImage。通过这样做:

var preImage = context.PreImage.ToEntity<EntityName>();

这给了我 preImage 所以没有改变的值。现在我尝试通过使用上下文来获取具有更改值的实体。

var update = context.GetEntity.ToEntity<EntityName();

但是我没有得到任何数据。

如何获取更新的数据?任何人都可以帮助我并告诉我为什么这不起作用。我希望这是足够的代码。

【问题讨论】:

    标签: c# plugins dynamics-crm-2011 dynamics-crm crm


    【解决方案1】:

    希望下面的代码对你有所帮助。

    protected void ExecuteYourPlugin(LocalPluginContext localContext)
    {
        IPluginExecutionContext pluginContext = localContext.PluginExecutionContext;
        // Get Target Entity
        var updateEntity = (Entity)pluginContext.InputParameters["Target"];
    
        // Get PreImage Entity
        var preEntity = (Entity)localContext.PluginExecutionContext.PreEntityImages["PreImage"];
    
        // Is in Update
        if(localContext.PluginExecutionContext.MessageName.ToLower() == "update")
        {
            var fieldName = string.Empty;
    
                // If Contains, Extract value from Target Entity
                if(updateEntity.Contains("new_fieldname"))
                {
                    // Cast the fields according their type
                    fieldName = updateEntity["new_fieldname"].toString();
                }
                // Else extract the value from preImage
                else if(preEntity .Contains("new_fieldname"))
                {
                    // Cast the fields according their type
                    fieldName = preEntity["new_fieldname"].toString();
                }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2021-03-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-01
      • 2014-08-27
      • 1970-01-01
      • 2016-01-06
      • 1970-01-01
      相关资源
      最近更新 更多