我正在尝试编写一个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.
后跟一个长令牌。我不明白如何创建“销售订单”以及如何获得更易理解的错误消息。
答案 0 :(得分:1)
您编写的代码是使用插件在另一个执行管道中创建salesorder。并且您已注册此插件步骤以在创建salesorder实体记录时运行。
因此,此代码将继续循环,以避免您可以使用depth属性来阻止死锁。
为了您的学习目的,请在其他实体上注册此插件步骤&amp;测试它。