首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Dynamic365号中正确创建SalesOrder

在Dynamic365号中正确创建SalesOrder
EN

Stack Overflow用户
提问于 2018-06-01 13:10:25
回答 1查看 397关注 0票数 0

我试图写一个动态365 CRM插件,我想在其中创建一个新的“销售订单”。

我有以下代码:

代码语言:javascript
复制
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“,以及如何获得更容易理解的错误消息。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-06-01 18:00:35

您编写的代码用于使用插件在另一个执行管道中创建salesorder。您注册了这个插件步骤,以便在创建salesorder实体记录本身时运行。

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

为了您的学习目的,在其他实体上注册这个插件步骤并测试它。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50644222

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档