3. Mai 2012 11:33
public void Execute(IServiceProvider serviceProvider)
{
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
ITracingService tracer = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
Entity targetEntity = null; // CRM 2011: Microsoft.Crm.Sdk.DynamicEntity -> Microsoft.Xrm.Sdk.Entity
if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
{
targetEntity = (Entity)context.InputParameters["Target"];
if (targetEntity.LogicalName != "product")
{
return;
}
}
else
{
return;
}
if (!targetEntity.Contains("new_allgemeinesproduktid"))
{
throw new InvalidPluginExecutionException("kein Allgemeines Produkt angegeben");
}
IOrganizationService service = factory.CreateOrganizationService(context.UserId);
EntityCollection result1 = findMyProductEntities(service, targetEntity);
Entity member;
if (!targetEntity.Contains("name"))
{
member = service.Retrieve("new_produktallgemein", ((EntityReference)targetEntity["new_allgemeinesproduktid"]).Id, new ColumnSet(true));
targetEntity.Attributes.Add("name", setName(member, targetEntity));
}
foreach (var item in result1.Entities)
{
member = service.Retrieve("new_produktallgemein", (Guid)item["new_produktallgemeinidtwo"], new ColumnSet(true));
createProduct(targetEntity, member, service);
}
}
private void createProduct(Entity target, Entity vorlage, IOrganizationService service)
{
Product pro = new Product();
pro.Name = setName(vorlage, target);
pro.IsKit = (bool)target["iskit"];
pro.new_allgemeinesProduktId = vorlage.ToEntityReference();
pro.new_von = (DateTime)target["new_von"];
pro.new_bis = (DateTime)target["new_bis"];
pro.ProductNumber = (string)target["productnumber"] + (string)vorlage["new_idnummer"];
pro.DefaultUoMScheduleId = (EntityReference)vorlage["new_einheitengruppe"];
pro.DefaultUoMId = (EntityReference)vorlage["new_standardeinheit"];
pro.QuantityDecimal = (int)target["quantitydecimal"];
service.Create(pro);
}
Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: Generic SQL error.Detail:
<OrganizationServiceFault xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/xrm/2011/Contracts">
<ErrorCode>-2147204784</ErrorCode>
<ErrorDetails xmlns:d2p1="http://schemas.datacontract.org/2004/07/System.Collections.Generic">
<KeyValuePairOfstringanyType>
<d2p1:key>CallStack</d2p1:key>
<d2p1:value xmlns:d4p1="http://www.w3.org/2001/XMLSchema" i:type="d4p1:string"> bei Microsoft.Crm.Extensibility.VersionedPluginProxyStepBase.Execute(PipelineExecutionContext context)
bei Microsoft.Crm.Extensibility.Pipeline.Execute(PipelineExecutionContext context)
bei Microsoft.Crm.Extensibility.MessageProcessor.Execute(PipelineExecutionContext context)
bei Microsoft.Crm.Extensibility.InternalMessageDispatcher.Execute(PipelineExecutionContext context)
bei Microsoft.Crm.Extensibility.ExternalMessageDispatcher.ExecuteInternal(IInProcessOrganizationServiceFactory serviceFactory, IPlatformMessageDispatcherFactory dispatcherFactory, String messageName, String requestName, Int32 primaryObjectTypeCode, Int32 secondaryObjectTypeCode, ParameterCollection fields, CorrelationToken correlationToken, CallerOriginToken originToken, UserAuth userAuth, Guid callerId, Guid transactionContextId, Int32 invocationSource, Nullable`1 requestId, Version endpointVersion)
bei Microsoft.Crm.Extensibility.OrganizationSdkServiceInternal.ExecuteRequest(OrganizationRequest request, CorrelationToken correlationToken, CallerOriginToken callerOriginToken, WebServiceType serviceType)
bei Microsoft.Crm.Extensibility.OrganizationSdkServiceInternal.Create(Entity entity, CorrelationToken correlationToken, CallerOriginToken callerOriginToken, WebServiceType serviceType)</d2p1:value>
</KeyValuePairOfstringanyType>
</ErrorDetails>
<Message>Generic SQL error.</Message>
<Timestamp>2012-05-03T09:30:36.6631056Z</Timestamp>
<InnerFault i:nil="true" />
</OrganizationServiceFault>
3. Mai 2012 14:43
4. Mai 2012 08:41
4. Mai 2012 09:41
4. Mai 2012 10:14
4. Mai 2012 10:57
4. Mai 2012 11:38
4. Mai 2012 12:19
4. Mai 2012 15:41
insert into [ProductBase]([DefaultUoMScheduleId], [OrganizationId], [ProductId], [ModifiedOnBehalfBy], [StateCode], [StatusCode], [CreatedBy], [ProductNumber], [TimeZoneRuleVersionNumber], [IsStockItem], [DefaultUoMId], [ModifiedOn], [QuantityDecimal], [ModifiedBy], [ProductTypeCode], [CreatedOn], [Name], [UTCConversionTimeZoneCode], [IsKit]) values ('a1b11bb0-aa87-e111-8709-00155d019a00', '509c0aa1-f2ad-474e-828c-0f4bb382fe69', '28636f65-eb95-e111-8630-00155d019a00', NULL, 0, 1, 'f44cbb9d-8384-e111-bf63-00155d019a00', '270-513', 0, 0, 'a2b11bb0-aa87-e111-8709-00155d019a00', '05/04/2012 13:16:45', 2, 'f44cbb9d-8384-e111-bf63-00155d019a00', 1, '05/04/2012 13:16:45', 'TS: Windows Communication Foundation Development with Microsoft .NET Framework 4 01.05.2012 04.05.2012', 110, 0);
insert into [ProductExtensionBase]([ProductId], [new_allgemeinesProduktId], [new_bis], [new_von]) values ('28636f65-eb95-e111-8630-00155d019a00', 'ec465ec2-9788-e111-8dba-00155d019a00', '05/03/2012 22:00:00', '04/30/2012 22:00:00')
[...]
Die INSERT-Anweisung steht in Konflikt mit der FOREIGN KEY-Einschränkung 'FK_ProductExtensionBase_ProductBase'. Der Konflikt trat in der CRM2011DBSN_MSCRM-Datenbank, Tabelle 'dbo.ProductBase', column 'ProductId' auf.
4. Mai 2012 16:55
Die INSERT-Anweisung steht in Konflikt mit der FOREIGN KEY-Einschränkung 'FK_ProductExtensionBase_ProductBase'. Der Konflikt trat in der CRM2011DBSN_MSCRM-Datenbank, Tabelle 'dbo.ProductBase', column 'ProductId' auf.
7. Mai 2012 09:05