web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested Answer

organizationService doesn't work in Plugin: Record not created without error message

(0) ShareShare
ReportReport
Posted on by 15

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;
}
}
}
}

I have the same question (0)
  • Bipin D365 Profile Picture
    28,983 Moderator on at

    Hi,

    Can you try checking if conditions is not null. If this field value is null then there is nothing to update in Dynamics.

    I don't think you are creating any record from plugin code.

    Also try debugging your code. Keep trace log and check.

    Please mark my answer verified if i were helpful

  • Dominik Mueller Profile Picture
    15 on at

    Thanks for your advice!

    The variable conditions is not null, the update should work like this.

    And you're completely right, I don't create a record in my plugin. That was a test I developed before to look if create works instead of update, but it didn't work either. So, the title of my forum question is not exactly right...

    Do you have some other ideas why the RetrieveMultiple works and the Update and Create don't?

  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Hello,

    My recommendation - master troubleshooting of plugins - www.youtube.com/watch

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 81 Super User 2025 Season 2

#2
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 49 Most Valuable Professional

#3
#ManoVerse Profile Picture

#ManoVerse 40

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans