Hi guys
I'm developing a plugin for Dynamics CRM 365 8.2.4.6 On-Premise. I get the OrganizationService and the target entity correctly, I can also do some RetrieveMultiple. The problem is that I cannot create or update a record. The code is running without an error message, but the record is not created in the CRM. Do you guys know what the problem could be? Maybe do I need the .NET-framework 4.6.2 for Dynamics 365 On-Premise environments?
Here are the specifications of my plugin:
.NET-Framework: 4.5.2
Nuget Microsoft.CrmSdk.CoreAssemblies: 8.2.0.2
In the code down here, the green code is working with the OrganizationService (I can retrieve records), the red code is not working.
public class Plugin : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
// Obtain the tracing service
ITracingService tracingService =
(ITracingService)serviceProvider.GetService(typeof(ITracingService));
// Obtain the execution context from the service provider.
IPluginExecutionContext context = (IPluginExecutionContext)
serviceProvider.GetService(typeof(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 target = (Entity)context.InputParameters["Target"];
// Obtain the organization service reference which you will need for
// web service calls.
IOrganizationServiceFactory serviceFactory =
(IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
try
{
var targetEntity = service.Retrieve(target.LogicalName, target.Id, new ColumnSet("as_entityname", "as_entityconditions"));
var conditions = targetEntity.GetAttributeValue<string>("as_entityconditions");
var query = new QueryExpression("as_currencyfield");
var condition = new ConditionExpression
{
AttributeName = "as_entityname",
Operator = ConditionOperator.Equal,
Values = {targetEntity.GetAttributeValue<string>("as_entityname")}
};
query.Criteria.AddCondition(condition);
var relatedCurrencyFieldsList = service.RetrieveMultiple(query).Entities.ToList();
foreach (var relatedCurrencyField in relatedCurrencyFieldsList)
{
var updateEntity = new Entity(relatedCurrencyField.LogicalName, relatedCurrencyField.Id);
updateEntity.Attributes.Add("as_entityconditions", conditions);
service.Update(updateEntity);
}
}
catch (FaultException<OrganizationServiceFault> ex)
{
throw new InvalidPluginExecutionException("An error occurred in Plugin SetConditionsOnCurrencyFieldEntities.Plugin.", ex);
}
catch (Exception ex)
{
tracingService.Trace("Plugin: {0}", ex.ToString());
throw;
}
}
}
}