【问题标题】:How to access the organization from within a plugin?如何从插件中访问组织?
【发布时间】:2013-08-08 09:36:43
【问题描述】:

我正在阅读一些写得很糟糕的代码,而我的大脑刚刚关闭,主要是由于沮丧,所以这个问题可能很简单。

我在插件中,我需要创建实体 Blobb 的新实例。鉴于我已经完成了查询表达式,我该如何执行它?我必须通过创建 OrganizationServiceProxy 对象还是可以使用发送到 Execute 方法的 IServiceProvider 实例?我正在使用它来获取上下文(即 IPluginExecutionContext 类型的对象),但我找不到具有执行查询表达式的方法的服务。

【问题讨论】:

  • 请移植您的代码。
  • 对不起,它只是一种类型。我的意思是发布您的代码而不是端口 :) 很高兴它对您有所帮助。
  • @Scorpion 什么类型?呐,我知道你的意思。只是开玩笑。当一个人在 typo 中打错字时,有点好笑。 :)
  • 天哪....我的错字问题... :) 我也应该加入english.stackexchange.com :)

标签: dynamics-crm-2011


【解决方案1】:

我想你正在寻找这个。你可以通过LocalPluginContext来使用Execute。

public class OrgPlugin: Plugin
{
    public OrgPlugin()
        : base(typeof(OrgPlugin))
    {
        base.RegisteredEvents.Add(new Tuple<int, string, string, Action<LocalPluginContext>>(20, "Create", "account", new Action<LocalPluginContext>(ExecuteOrgPlugin)));
    }

    protected void ExecuteOrgPlugin(LocalPluginContext localContext)
    {
        Blobb blobb = new Blobb();
        blobb["new_name"] = "abc";
        // Other attributes here
        localContext.OrganizationService.Execute(blobb);
    }
}

编辑

您可以从localContext.OrganizationService 中提取OrganizationService

IOrganizationService service = localContext.OrganizationService;

【讨论】:

    猜你喜欢
    • 2023-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-04
    • 1970-01-01
    • 1970-01-01
    • 2012-01-05
    • 1970-01-01
    相关资源
    最近更新 更多