gpt4 book ai didi

dynamics-crm-2011 - CRM 2011 Post Operation Plugin - 尝试保存引用实体时不存在主要实体

转载 作者:行者123 更新时间:2023-12-01 02:34:53 24 4
gpt4 key购买 nike

我正在尝试为现场 Dynamics CRM 2011 安装创建插件。

我已经注册了插件如下:

  • 留言:创建
  • 主要实体:联系方式
  • 执行阶段:术后
  • 执行方式:同步
  • 执行顺序:1

  • 插件代码如下:

    public void Execute(IServiceProvider serviceProvider)
    {
    var pluginExecContext = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

    var orgServiceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
    var orgService = orgServiceFactory.CreateOrganizationService(pluginExecContext.UserId);
    var orgServiceContext = new OrganizationServiceContext(orgService);

    var tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));

    if (pluginExecContext.InputParameters.Contains("Target") &&
    pluginExecContext.InputParameters["Target"] is Entity)
    {
    var target = (Entity)pluginExecContext.InputParameters["Target"];

    if (target.LogicalName != Contact.EntityLogicalName)
    return;

    try
    {
    var customerServicesUser = orgServiceContext.CreateQuery(SystemUser.EntityLogicalName)
    .Where(x => (string)x["fullname"] == "Customer Services").FirstOrDefault();

    if (customerServicesUser == null)
    throw new InvalidPluginExecutionException("No Customer Services user exists.");

    var sendEmail = new cdi_sendemail
    {
    cdi_fromrecordowner = false,
    cdi_contactid = new EntityReference(Contact.EntityLogicalName, pluginExecContext.PrimaryEntityId),
    cdi_fromid = new EntityReference(SystemUser.EntityLogicalName, customerServicesUser.Id)
    };

    tracingService.Trace("PostContactCreate plug-in: Creating the cdi_sendemail entity.");
    orgService.Create(sendEmail);
    }
    catch (FaultException<OrganizationServiceFault> ex)
    {
    throw new InvalidPluginExecutionException("An error occurred in the PostContactCreate plug-in.", ex);
    }
    catch (Exception ex)
    {
    tracingService.Trace("PostContactCreate plug-in: {0}", ex.ToString());
    throw;
    }
    }
    }

    当我使用 pluginregistration 工具分析插件并调试错误异常时,我收到以下错误:

    Contact With Id = abbc7e0a-20a0-e111-a36e-005056860004 Does Not Exist.



    我有点理解插件正在尚未提交的 SQL 事务中执行。 CRM SDK 示例中的“FollowupPlugin”也创建了一个引用实体,声明它需要异步注册,这也是有意义的,因为它允许提交 SQL 事务。

    所以我想我的问题是,如何在同步插件中创建引用实体?

    最佳答案

    看着SDK example for a very similar example - 我认为您需要在沙箱中注册。

    Register this plug-in for an account entity, on the Create message, and in asynchronous mode. Alternately, you can register the plug-in on a post-event in the sandbox.

    关于dynamics-crm-2011 - CRM 2011 Post Operation Plugin - 尝试保存引用实体时不存在主要实体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10638152/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com