【问题标题】:Properly creating a SalesOrder in Dynamics 365在 Dynamics 365 中正确创建 SalesOrder
【发布时间】:2018-06-01 13:10:25
【问题描述】:

我正在尝试编写一个 Dynamics 365 CRM 插件,我想在其中创建一个新的“销售订单”。

我有以下代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.Text;
using System.Threading.Tasks;

// Microsoft Dynamics CRM namespace(s)
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;

namespace Microsoft.Crm.Sdk.Samples
{
    public class OrderTest : IPlugin
    {
        public void Execute(IServiceProvider serviceProvider)
        {
            ITracingService tracingService =
                (ITracingService)serviceProvider.GetService(typeof(ITracingService));

            // Obtain the execution context from the service provider.
            Microsoft.Xrm.Sdk.IPluginExecutionContext context = (Microsoft.Xrm.Sdk.IPluginExecutionContext)
                serviceProvider.GetService(typeof(Microsoft.Xrm.Sdk.IPluginExecutionContext));

            // The InputParameters collection contains all the data passed in the message request.
            if (context.InputParameters.Contains("Target") &&
                context.InputParameters["Target"] is Entity)
            {
                // Obtain the target entity from the input parameters.
                Entity entity = (Entity)context.InputParameters["Target"];

                if (entity.LogicalName != "salesorder")
                    return;

                try
                {
                    Entity salesorder = new Entity("salesorder");

                    salesorder["name"] = "order test";

                    IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
                    IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
                    tracingService.Trace("OrderTestPlugin: Creating the order test.");
                    Guid orderId = service.Create(salesorder);

                }
                catch (FaultException<OrganizationServiceFault> ex)
                {
                    throw new InvalidPluginExecutionException("An error occurred in the OrderTest plug-in.", ex);
                }
                //</snippetFollowupPlugin3>

                catch (Exception ex)
                {
                    tracingService.Trace("OrderTestPlugin: {0}", ex.ToString());
                    throw;
                }

            }
        }
    }
}

我的问题是创建销售订单失败。我得到的错误信息是没有用的。它说:Download the details and load with Plug-in Profiler. 后跟一个长令牌。我不明白如何创建“salesorder”以及如何获得更易于理解的错误消息。

【问题讨论】:

  • 以上代码用于使用插件在另一个执行管道中创建销售订单。您在什么消息下注册了此插件步骤?已经检查目标作为销售订单?插件分析器安装了吗?
  • 我注册了这个插件步骤如下:消息:创建,主要实体:salesorder,事件管道:PreValidation,执行模式:同步。我还在注册工具中安装了插件分析器。
  • 出于测试目的,我尝试在从动态用户界面创建新订单时以编程方式创建新销售订单。
  • 好的。如果您在创建另一个销售订单时创建销售订单,这将继续循环.. 为了测试或学习,请在另一个实体创建中进行。了解插件执行深度......
  • 谢谢,更改主要实体有帮助。

标签: c# dynamics-crm microsoft-dynamics dynamics-crm-365


【解决方案1】:

您编写的代码用于使用插件在另一个执行管道中创建销售订单。并且您注册了此插件步骤以在创建 salesorder 实体记录时运行。

因此,这段代码将继续循环,以避免您可以使用深度属性来停止死锁。

为了您的学习目的,在其他实体上注册此插件步骤并对其进行测试。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-10-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多