我试图写一个动态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“,以及如何获得更容易理解的错误消息。
发布于 2018-06-01 18:00:35
您编写的代码用于使用插件在另一个执行管道中创建salesorder。您注册了这个插件步骤,以便在创建salesorder实体记录本身时运行。
因此,这段代码将继续循环,以避免使用深度属性来停止死锁。
为了您的学习目的,在其他实体上注册这个插件步骤并测试它。
https://stackoverflow.com/questions/50644222
复制相似问题