在 Dynamics 365 中正确创建 SalesOrder
Properly creating a SalesOrder in Dynamics 365
我正在尝试编写一个 Dynamics 365 CRM 插件,我想在其中创建一个新的 "salesorder"。
我有以下代码:
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" 以及如何获得更易于理解的错误消息。
您编写的代码用于使用插件在另一个执行管道中创建销售订单。并且您在创建销售订单实体记录本身时将此插件步骤注册到 运行。
因此这段代码将继续循环,以避免您可以使用深度 属性 来停止死锁。
为了您的学习目的,请在其他实体上注册此插件步骤并对其进行测试。
我正在尝试编写一个 Dynamics 365 CRM 插件,我想在其中创建一个新的 "salesorder"。
我有以下代码:
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" 以及如何获得更易于理解的错误消息。
您编写的代码用于使用插件在另一个执行管道中创建销售订单。并且您在创建销售订单实体记录本身时将此插件步骤注册到 运行。
因此这段代码将继续循环,以避免您可以使用深度 属性 来停止死锁。
为了您的学习目的,请在其他实体上注册此插件步骤并对其进行测试。