Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Suggested answer

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

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

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: organizationService doesn't work in Plugin: Record not created without error message

    Hello,

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

  • Dominik Mueller Profile Picture
    Dominik Mueller 15 on at
    RE: organizationService doesn't work in Plugin: Record not created without error message

    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?

  • Bipin D365 Profile Picture
    Bipin D365 28,964 Super User 2024 Season 1 on at
    RE: organizationService doesn't work in Plugin: Record not created without error message

    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

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans