Use Workflow to fill a field with the stage name

As you might know, in the Opportunity entity there was a field that saves the text of each stage, but if you want that for other entities that field might not be available.
There was a way that worked until the version 8.2, where you build a workflow to run in the entity that you have the BPF and then save the Process Stage Name to the field that you created.
In the new version that isn’t working very well, from my tests it is only saving the previous stage name (the stage that was before the active).
Now to have the actual stage I had to do like this:

-With the next BPF from 8.2, this isn’t working well since it is only putting in the field the previous stage.
-To achieve the what you want, you need to create a workflow that is running in the BPF entity of the process, for example, Phone to Case Process.
-Create a custom field to save the text.
-You put the workflow in sync, then select to run when “Process is applied” and “Process changes” then you select the field “Active Stage Id”
-Then you insert the step Update Record, change it to “Incident Id (Case)” in the workflow and in the properties you add to the field that you want to save the text of the process. On the right options Look for: Active Stage Id (Process Stage) and then the field Process Stage.

It should look like this:

Advertisements

CRM Audit info dissapeared

Some of the New Value data might disappear (have the broken icon instead of the value) when you import a solution that disables the Audit of the entity or if the Audit is already disabled and then you enable Audit.
It is a known issue and if you are working on online you will need to create a Service Request to the Support.
If you are OnPrem you will need to run the following SQL script to check and then clean the records:

Select * from AuditBase WHERE action = 104 OR action = 102
Action = 104 | Any Auditing Changes that are made at Organization level would get captured with code 104.

Action = 102 | Any Auditing Changes that are made at Entity level would get captured with code 102.

In order to retrieve the Audit value from the DB, we would need to run the following command:

DELETE from AuditBase WHERE action = 104 AND CreatedOn > ‘<date>’ || Action = 104 or 102, depending on the results we get the above SELECT query

After this, the values will show again.

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

 

Changed sitemap and can’t access to the instance

There are a couple of issues when you drag or change the sitemap in the SiteMap editor in Dynamics 365.
If you get this problem and can’t access the instance anymore, try to use the XrmToolbox, there is a plugin called SiteMap Editor that try to load your sitemap from there.
If it loads, you just need to correct the faulty subarea or group and then Update the sitemap again to the instance.
If when you try to load you get a parse error message where it should show the sitemap, then it is corrupted and you can reset the sitemap to the default (going to More Actions in the tool submenu), or if you have a backup of you sitemap, just create an new file.xml, click on open sitemap, select the file and then upload sitemap.
This should solve your issue.
You can also find the structure of the Sitemap in the SDK.

Clicking on the Phone field to open Skype call

It is easy to use Skype to call a contact or company.
You need to have a field that is with the phone number format so that will be clickable. When you press the number it will open a window asking if you want to call from Skype or Skype for Business (you will need to check what is configured in the System Settings->General tab).
After that, it will show the Skype window to make the call and simultaneously it will open a phone call activity in the CRM so you can start writing any information about the call.

clicktophonecall

Hope this helps

Performance Analysis online

When we have a problem in Dynamics CRM instance of a client, Microsoft has available an online page that we use to do some screening of what may be happening to the instance.
For that we must go to the following URL: https://<OrganizationName>/tools/diagnostics/diag.aspx (change the with the client organization) and from there we will have a page with some information that will be analyzed after we press the Run button.

For example https://myorg.crm4.dynamics.com/tools/diagnostics/diag.aspx

performance_online

From the Results, we can analyze the Latency, Bandwith, Browser Info and much more.

Hope this helps.

Debugging Javascript with Dev Tools

When we are developing in Javascript, sometimes we need to debug the code when we found an error. You can easily do debug with the Dev Tools of the browser.
If you press F12 on your browser you have access to a window like shown below and move to the debugger tab and your code you have a debugger; condition in your code, when you execute the action you will get the debug active and you can start moving on your code to see where the problem is.

debugging-javascript-with-dev-tools

You can also search for the web resource file name and make a breakpoint on the DevTools instead if you don’t want to have the debugger; written in your code.

crm-diagnostics1

Hope this helps

My Recent Items

Sometimes in our daily work, we access some records many times a day, and jumping from one records to another, going always to the records list might not be very practical.

You can view your recent visited records going to the top menu and clicking in the Recently Viewed Items.

recent_items1

After that it will show you your Recent Views or Recent Records, making it easy to jump between records.

recent_items2

 

Hope this helps.

How to impersonate in Plugins

Hello,

The other day a colleague question me how he could impersonate via plugin, so the records were updated with a person that had permissions, instead of the person that didn’t have.

There is two way you can do it, first and simpler is when you go to the registration plugin tool when you are editing the step you can put a specific person impersonating that plugin. The catch is that it always be that person.

Like this:
registrationplugin_impersonate

Or you can do it via code, and you can do filters to see when it should impersonate or not. Just need to set the user id.

Like this:

code_impersonate

Hope this helps.