27.03.2012, 17:56 | #1 |
Участник
|
CRM 2011, вопрос по плагину
товарищи, добрый день!
подскажите, пожалуйста, по плагину.. он делает следующее - обновляет сущность new_zayavka, создает Заказ, прописывает в Заказ название, прайслист, валюту, клиента и заблокированы ли цены. Эта часть отрабатывает как надо. Но я захотел добавить еще и продукт в этот Заказ, вот тут-то мне Плагин и выдал ошибку "the parent id is missing". Плагин повешен на Update сущности new_zayavka, на Pre-validation. спасибо! X++: Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: The parent id is missing.Detail: <OrganizationServiceFault xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/xrm/2011/Contracts"> <ErrorCode>-2147220970</ErrorCode> <ErrorDetails xmlns:d2p1="http://schemas.datacontract.org/2004/07/System.Collections.Generic" /> <Message>The parent id is missing.</Message> <Timestamp>2012-03-27T13:26:50.6738765Z</Timestamp> <InnerFault i:nil="true" /> <TraceText> [ClassLibrary7: CreateSalesOrder.Order] [64e3abde-0978-e111-af6d-000c29c05d09: CreateSalesOrder.Order: Update of new_zayavka] Order: System.ServiceModel.FaultException`1[Microsoft.Xrm.Sdk.OrganizationServiceFault]: The parent id is missing. ( Microsoft.Xrm.Sdk.OrganizationServiceFault). </TraceText> </OrganizationServiceFault> X++: using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.Xrm.Sdk; using Microsoft.Xrm.Sdk.Client; using Microsoft.Xrm.Sdk.Query; using System.ServiceModel; using System.ServiceModel.Description; namespace CreateSalesOrder { public class Order : IPlugin { public void Execute(IServiceProvider serviceProvider) { ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService)); try { IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext)); Entity record = (Entity)context.InputParameters["Target"]; if (record.LogicalName == "new_zayavka") { record["new_inn"] = "sdf"; record["new_name_nai"] = record["new_inn"]; Entity pricelevel = new Entity("pricelevel"); Entity currency = new Entity("transactioncurrency"); Entity account = new Entity("account"); bool vispricelocked = false; Entity salesorder = new Entity("salesorder"); salesorder["name"] = "TEST"; salesorder["pricelevelid"] = new EntityReference(pricelevel.LogicalName, new Guid("156ABFBD-3704-DF11-9297-005056C00008")); salesorder["transactioncurrencyid"] = new EntityReference(currency.LogicalName, new Guid("9E79B15D-1937-E111-A8B6-08002739EA86")); salesorder["customerid"] = new EntityReference(account.LogicalName, new Guid("46053320-E952-E111-81DB-000C29C05D09")); salesorder["ispricelocked"] = vispricelocked; // Obtain the organization service reference. IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory)); IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId); service.Create(salesorder); Guid id_1 = new Guid(salesorder["salesorderid"].ToString()); Entity salesorderdetail = new Entity("salesorderdetail"); salesorderdetail["new_orda"] = new EntityReference("salesorder", id_1); Entity product = new Entity("product"); Entity uom = new Entity("uom"); salesorderdetail["productid"] = new EntityReference(product.LogicalName, new Guid("AC341411-4347-E111-9250-000C29C05D09")); salesorderdetail["uomid"] = new EntityReference(uom.LogicalName, new Guid("5D15C954-A08E-DB11-934C-000E0C6AB271")); IOrganizationServiceFactory serviceFactory1 = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory)); IOrganizationService service1 = serviceFactory1.CreateOrganizationService(context.UserId); service1.Create(salesorderdetail); } } catch (Exception ex) { tracingService.Trace("Order: {0}", ex.ToString()); throw; } } } } |
|
|
|