3
votes

I work with Microsoft Dynamics CRM 2011. Another service communicates with CRM via IOrganizationService. In order to improve performance, I want to reduce the number of distinct calls. Particularly, I wonder if it is possible to obtain newly created or updated entity with all the fields that are initialized during plugins execution without making an extra call to the IOrganizationService.

As far as I know, it is possible in the newer versions of Microsoft Dynamics CRM. But is there a way it can be done in Microsoft Dynamics CRM 2011?

2

2 Answers

2
votes

The link you are referring is for web api specific scenario.

In all plugin execution context, either create or update, pre or post operation we can get all the attributes of that particular record in target entity object from the context itself.

// 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 entity = (Entity)context.InputParameters["Target"];

For update, you can register Images to get all the other attribute values (pre-Image) which are not updated in that particular transaction, without making another service call.

Read more

1
votes

The answer is No in any version of CRM using OrganizationService calls. Assuming you have a scenario like the following:

Entity contact = new Entity("contact")
Guid contactId = _service.Create(contact);
Entity refreshedContact = _service.Retrieve("contact", contactId, new ColumnSet("new_fieldupdatedbyplugin"));

There is no more efficient way to get the value of contact.new_fieldupdatedbyplugin

Within the context of plugin execution, Arun is certainly right, you can register a plugin on a Post execution step and reference the PostImage which will include all values updated by all plugins running on Pre execution steps. If you wanted to trigger some action based on a value set by a pre plugin, you could do it in a post plugin.