Plugin Registered in the RetrieveMultiple for all entities

When you are trying to install a solution from the Office 365 Admin Center, but you get a generic error and it is saying to try again later, this might be related to an issue with a Retrieve Multiple plugin that is registered for all entities.

You go to Office 365, then you go to Admin. After that in the left menu you expand Admin and click in Dynamics 365, it will open the Instance Picker page with all the instances that you have.

After that you select the instance and press the Solution option, it should open a new page where you can install/update/uninstall solutions to that CRM instance. If it isn’t opening and you are getting an error it might be the problem that I described before.

You need to open the solution and go to the SDK messages and check the message column and filter by the message RetrieveMultiple, or if you know the assembly, open the PluginRegistrationTool and disable the plugin and try to open the solutions page again in the Instance Picker page.

Hope this helps.


Moving between BPF stages programmatically

This is a simple code example that you can use to do move stages of a Business Process Flow (it can be improved, for example, to not have the stages id in the code). Also, I was using early bound class for this example. The field TraversedPath needs to be updated accordingly the stage that you are moving, so if you are going forward you need to add the stages, if you are going backward you need to remove the stages.

I have 3 Opportunities in the system:

  • Opp1 -> Stage1
  • Opp2 -> Stage2
  • Opp3 -> Stage3

And want to change the stages to:

  • Opp1 -> Stage3
  • Opp2 -> Stage1
  • Opp3 -> Stage2
   string connectionString = GetServiceConfiguration();

   CrmServiceClient conn = new CrmServiceClient(connectionString);
   _serviceProxy = (IOrganizationService)conn.OrganizationWebProxyClient != null ? (IOrganizationService)conn.OrganizationWebProxyClient : (IOrganizationService)conn.OrganizationServiceProxy;

   string fetchXml = @"";

   EntityCollection result = _serviceProxy.RetrieveMultiple(new FetchExpression(fetchXml));
   string processid = "3E8EBEE6-A2BC-4451-9C5F-B146B085413A";
   string stage1 = "6b9ce798-221a-4260-90b2-2a95ed51a5bc";
   string stage2 = "650e06b4-789b-46c1-822b-0da76bedb1ed";
   string stage3 = "d3ca8878-8d7b-47b9-852d-fcd838790cfd";
   foreach (Opportunity opp in result.Entities)
      string id = opp.Id.ToString();

      Entity op = new Entity("opportunity");
      op.Id = opp.Id;

      if (opp.StageId.Value.ToString().ToUpper() == stage1.ToUpper())
         op["processid"] = new Guid(processid);
         op["stageid"] = new Guid(stage3);
         op["traversedpath"] = new Guid(stage1.ToLower()) + "," + new Guid(stage2.ToLower()) + "," + new Guid(stage3.ToLower()).ToString();
      if (opp.StageId.Value.ToString().ToUpper() == stage2.ToUpper())
         op["processid"] = new Guid(processid);
         op["stageid"] = new Guid(stage1);
         op["traversedpath"] = new Guid(stage1.ToLower()).ToString();
      if (opp.StageId.Value.ToString().ToUpper() == stage3.ToUpper())
         op["processid"] = new Guid(processid);
         op["stageid"] = new Guid(stage2);
         op["traversedpath"] = new Guid(stage1.ToLower()) + "," + new Guid(stage2.ToLower()).ToString();

catch (Exception ex)


Infinite loop on Plugin – Dynamics CRM

Have you ever had a situation where you want to use a plugin when a state of a record changes, and the logic needed to implement at the end of the code is to set that record again in the same state?

For instance, if you have a plugin registered in the Quote entity, message SetState/SetStateDynamicEntity and when you activate the Quote, the plugin starts. Your logic in the plugin says that is going to search for some records that are Active, put them in Draft state, changing the necessary fields and Activate it again.

What do we get? The infinite loop….

There is always a problem to these types of plugin, but sometimes you need to do it and how can you get around this problem? We can add a bool field, hidden in the form, to validate this operation at the begining of the plugin and when we first run the plugin, we change that field so the next time it tries to run, it will exit the execution.
It is just one more field, that is hidden in the form and maybe it is easier to manage (you need to remember that if is when you Activate, then when you Revise you need to revert the field), but sometimes there are so many fields that maybe it is better not to implement like that (and not so elegant).

There is another way to do this. You can build a plugin that can be used in a workflow (a workflow plugin), you have the same plugin logic implemented like you have in a normal plugin, but just need to change some of the execution steps of the plugin and how it is registered. If you use the Developer Toolkit for Visual Studio you can do it easily.

1-Create a Workflow Plugin class

Create Workflow Plugin

2-Add Input Parameters if necessary

Input Parameters
Next part of the plugin

3-Deploy your workflow plugin (if you are using Developer ToolKit, otherwise you register via PluginRegistrationTool)

Deploy Workflow Plugin

4-Create your workflow – This workflow can run on a changing of a field, changing of status, etc. In our case we had a button that called this workflow to Activate the Quote and then run my workflow plugin

Create Workflow.

5-Add the step to run your plugin

Choose the plugin

6-Choose the input – After you have added the step you can insert the input to the plugin

Step added
Input from fields

After this, everytime you can this plugin, automatic or via javascript it will run the plugin too.

If you want to just prevent that the plugin goes in an infite loop, you can use Deep property to check if already run.

if (context.Depth > 1) { return; }

Hope this helps.