Workflow Process Corruption

When you have a workflow that is calling in a step a Custom Workflow Activity and you putting a workflow in draft, the Condition Expressions show as “Invalid Condition expression”. When you try to re-activate the workflow it isn’t possible because of the conditions.

This issue might appear if you changed the internal name of the input/output parameter and published the plugin. It will make the condition invalid because, the parameter that was used in the create/update step that is inside the condition is invalid, it is not recognizing the parameter. You need to remove the step and add it again.

Doing the deletion of the step and was able to change the condition branch and redo the Invalid condition expressions and after that, it was able to publish the workflow. Then added the step again. That way it was using the correct output parameter schema name.

Hope this helps.

Advertisements

Invalid User Authorization

When you get an error like this, when you try to open a Workflow that is in Draft mode, check first if you are using Custom Workflow Activities in that workflow and if the Custom Workflow is update with the most recent dll’s for the version of your Dynamics CRM instance.

I had a issue like that and updating the dll’s solved the problem.

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
try
{
   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();
      }

      _serviceProxy.Update(op);
   }
}
catch (Exception ex)
{
   throw;
}