Answered by:
delete the same record when creating the record in msccrm 2011 through plugin

Question
-
Dear all ;
i have a situation i have a plugin which is registered on create of appointment as a post operation . what i am doing in the plugin if the appointment is being created i want to delete the same record becasue the plugin i think it should delete the record but is not it is giving me the following error
here is the error
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" />
<Message>Generic SQL error.</Message>
<Timestamp>2013-03-15T13:16:57.6235071Z</Timestamp>
<InnerFault i:nil="true" />
<TraceText i:nil="true" />
</OrganizationServiceFault>
here is my code
public void Execute(IServiceProvider serviceProvider)
{
// Obtain the execution context from the service provider.
Microsoft.Xrm.Sdk.IPluginExecutionContext context = (Microsoft.Xrm.Sdk.IPluginExecutionContext)
serviceProvider.GetService(typeof(Microsoft.Xrm.Sdk.IPluginExecutionContext));
if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
{
if (context.MessageName == "Update")
{
if (context.Depth > 1)
{
return;
}
}
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
Entity entity = (Entity)context.InputParameters["Target"];
Entity appointment = service.Retrieve(entity.LogicalName, entity.Id, new ColumnSet(true));
//service.Delete("appointment", new Guid("238A13A7-718D-E211-8B75-984BE16D9F11"));
service.Delete("appointment", appointment.Id);
}
}Friday, March 15, 2013 1:29 PM
Answers
-
Hi Anwar,
Can you please try registering the plugin in Asynch mode and check whether it is working.
Bharath.
- Marked as answer by anwar_addi Friday, March 15, 2013 2:03 PM
- Unmarked as answer by anwar_addi Friday, March 15, 2013 2:32 PM
- Marked as answer by anwar_addi Friday, March 15, 2013 2:46 PM
Friday, March 15, 2013 1:53 PM
All replies
-
Hi Anwar,
Can you please try registering the plugin in Asynch mode and check whether it is working.
Bharath.
- Marked as answer by anwar_addi Friday, March 15, 2013 2:03 PM
- Unmarked as answer by anwar_addi Friday, March 15, 2013 2:32 PM
- Marked as answer by anwar_addi Friday, March 15, 2013 2:46 PM
Friday, March 15, 2013 1:53 PM -
not doing what i am looking for i have to create anotther record in another custom entity then delet the appointmentFriday, March 15, 2013 2:34 PM
-
thanks sortedFriday, March 15, 2013 2:48 PM