Home › Dynamics 365 Customer Engagement (CRM) › Dynamics 365 Calling Update in SDK.REST Invokes Retrieve
Dynamics 365 Customer Engagement (CRM) · Mar 13, 2018 · 2 MIN READ

Dynamics 365 Calling Update in SDK.REST Invokes Retrieve

In this post we will look at how calling the update method in SDK.REST causes a retrieve to run as well. This is something to note as you may have plugins that run on the retrieve of an entity, which may cause unintended consequences if not handled properly.

Let’s create a plugin that will run on the Update of an account:

Add the plugin assemblies through NuGet:

And the code. We will simply write to the Plugin Trace Log when the update plugin has been invoked:

[sourcecode language=”CSharp”] using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Microsoft.Xrm.Sdk;

namespace Carl.UpdateAccountPlugin
{
public class UpdatePlugin : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
tracingService.Trace("Update Plugin has Run");
}
}
}
[/sourcecode]

Add a strong name to the assembly.

Let’s register this against the Account Update using the Plugin Registration Tool:

Now let’s create a plugin to run on Retrieve of an Account:

Add the plugin assemblies through NuGet:

Add the code:

[sourcecode language=”CSharp”] using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Microsoft.Xrm.Sdk;

namespace Carl.RetrieveAccountPlugin
{
public class RetrievePlugin : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
tracingService.Trace("Retrieve Plugin has Run");
}
}
}
[/sourcecode]

Add a strong name to the assembly.

Now let’s register this on Account Retrieve:

Now we have the plugins ready to run.

Let’s try doing an update using the CRM REST Builder.

Open the REST Builder:

Create a request to update an account using SDK.REST:

You can see that the Update and Retrieve plugins have both been run even though we only called Update:

Now let’s create a request using the WebAPI:

Run the request to update the account:

Only the update runs and the retrieve is not called:

Using the WebApi is one way you can avoid the retrieve running if required.

Carl de Souza
Keep learning. Keep building.

Explore AI, agents & Microsoft technology.

I share practical ideas, tutorials, and videos about AI, AI agents, Microsoft technologies, and the Power Platform.

Subscribe on YouTube →
Carl de Souza Enterprise Architect at Microsoft · AI Technology Expert

Leave a Reply

Your email address will not be published. Required fields are marked *

Carl de Souza
KEEP LEARNING. KEEP BUILDING.

Explore AI, agents & Microsoft technology.

I share practical ideas, tutorials, and videos about AI, AI agents, Microsoft technologies, and the Power Platform.