1

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

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

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

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

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

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

4

1 回答 1

2

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

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();
            }
    }
}
于 2013-08-09T10:10:33.767 回答