Microsoft Dynamics CRM not working? check these common causes

I started up the DEV server too start my CRM dev this morning only to be confronted with a big fat error

CRM ERROR

 

 

The same error happened on every page, so it’s a fundamental error.

Yesterday IT sent an email warning me they would be gently powering down the servers for some maintenance (I bet they really just turned them off).

These common errors are another bonus of companies moving to the cloud because these problems won’t occur or will be fixed by Microsoft.

 

Check the time on the server

Checking the time on the server seems an odd thing to do, but if the time on the server is greater than 5 minutes out from your PC then CRM will fail to authenticate the user.  This is a common problem which pops up and to resolve this you need to get the IT team (or you if you don’t have one) to make sure you setting the time on the server properly (e.g. the same as the PC’s) so it stops the servers time drifting.

 

Check the CRM Asynchronous services

This should be your first thing to check because if the ASYNC services have stopped then CRM will stop working.  If you want to learn more about CRM Asyncs, you can go here

Asynchronous service in Microsoft Dynamics CRM

To see if the Async services are running, Microsoft have a document for starting and stopping 

  1. Navigate to Start, select Administrative Tools, then click Services.

You should find there are four CRM Async services and you can see if they are started

CRM async

The Async processing service is usually the cause of CRM not working.

 

The problem displayed on this page was caused

 

If you have restarted the Asyncs and CRM is still not working

Check IIS is up and running

go to the Start menu

type IIS

It will bring up Internet Information Services (IIS) Manager

IIS is the webserver which hosts the Microsoft Dynamics CRM website.  Some times you can find this may be stopped (very very rarely but its something to check, so we can rule it out)

There are a couple of things to check

 

CRM Application pools are running

CRM web app will have an application pool to run the web app, you need to double check its started and running.  The app pool will usually be set to a service account, the main reason you use a service account is because you don’t need to reset the password every 60 days.  Sometimes this setting won’t have been set and the app pool password will change and until someone goes in and puts/resets the password the CRM App pool will stop working.  When the CRM app pool stops working, CRM stops working.

Its worth noting if any of the other app pools are not started because they may be stopped on purpose or maybe have been stopped accidently.

you cann see the CRMAppPool below

app pools

 

 

Is the CRM Website up

if you click on the CRM website called Microsoft Dynamics CRM then the details of the web app will appear on the right, you need to check the start is greyed out (which means it is selected)

IIS CRM up

 

World Wide Web Publishing Service

There is also a service which controls if IIS is up and running and this is called the World Wide Web Publishing Service (named in the 1990’s I should imagine, not many times you see the words of WWW).  This can be turned off to stop IIS springing back to life after the server has been rebooted.

 

SQL Server

I often think of CRM as a web application to show the contents of the CRM SQL database.  If the SQL CRM instance is down, SQL server is off or can’t be contacted then CRM will stop working.

If CRM isn’t working you need to check the SQL server (usually on a different server) is up and running and the CRM instances are running.

 

 

Windows Event Viewer

They are some common things to check if CRM isn’t working but you will also need to check for some pointers for other errors.  The place I usually start is by checking the Event Viewer log on the CRM server.

Go to the CRM Server

Start Menu – type in Event Viewer

or

Control Panel –> Administrative Tools –> Event Viewer

 

Windows Logs –> Application

Look at the errors and warnings to see if there is anything which might point you in the direction of the potential error.  It’s unlikely you will actually get an error, usually I find it’s a warning and the warning will point you in the direction of the cause of CRM not working.

 

here is the logs from the server for the error shown at the top of the blog

event viewer logs

 

You can see there are a view warnings, a .NET, a sandbox.  Be warned there is often a lot of noise in the event logs (e.g. warning and errors which are not important).

I lookeda the .NET error

 

Process information:
Process ID: 5348
Process name: w3wp.exe
Account name: DEV\CRMAPPPOOL

Exception information:
Exception type: CrmException
Exception message: The plug-in execution failed because no Sandbox Hosts are currently available. Please check that you have a Sandbox server configured and that it is running.
System.ServiceModel.EndpointNotFoundException: Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support: #72E41A64
at Microsoft.Crm.Application.Platform.ServiceCommands.PlatformCommand.XrmExecuteInternal()
at Microsoft.Crm.Application.Platform.ServiceCommands.RetrieveMultipleCommand.Execute()
at Microsoft.Crm.Caching.DefaultSavedQueryIdCacheLoader.LoadCacheData(SavedQueryIdCacheKey key, IOrganizationContext context)
at Microsoft.Crm.Caching.CrmSharedMultiOrgCache`2.LookupEntry(TKey key, IOrganizationContext context)
at Microsoft.Crm.Caching.DefaultSavedQueryIdsCache.TryLookupEntry(Int32 objectType, Int32 savedQueryType)
at Microsoft.Crm.Application.Components.Sdk.FormControls.Web.LookupControl.ConfigureControl()
at Microsoft.Crm.Application.Components.UI.CrmUIControlBase.ConfigureControlInternal()

 

It pointed to the Sandbox service and when I checked the CRM services, I saw the sandbox service was stopped.  I started the sandbox service and CRM popped back into life.

Advertisements

CRM 2013 – Convert Email HTML to Plain Text

I have had this request from a few customers over the years and it’s converting and using the description of an email is trickier than you initially think it will be.  This is a question which often appears on the CRM forum quite regularly as well.

The reason for this is although the email looks like plain text when you see it in CRM, when you get the value of the Email entity description (main body of the email) you will also get all the HTML tags.

The scenario I had when I was doing this was the customer wanted to convert an email into a case and get the values from description.

So to do this I had to strip out the HTML tags and a few other things, which I did using a plugin

if you have to do this here a couple

This blog post is excellent

http://ashwaniashwin.wordpress.com/2014/04/16/convert-html-to-plain-text-for-copying-email-message-in-crm-2011-2013/

C# code

http://aliraza.wordpress.com/2007/07/05/how-to-remove-html-tags-from-string-in-c/

A sample plugin

http://blogs.msdn.com/b/ukcrm/archive/2008/07/10/converting-html-e-mail-to-plain-text.aspx

 

Recently I saw Steve Green had created a CRM Video going through the process and  I thought I would promote the video on the blog because he also has a link to the code here https://dl.dropboxusercontent.com/u/4041841/CRMDemo2014.zip

 

 

I would also recommend anyone who wants to learn CRM development to go through Steve’s other CRM videos, many of them are in CRM 2011 but the code would still work in CRM 2013.

CRM 2011 – UnRecognized ‘Edm.Guid’ literal ‘guid’null’

A user had reported this error and the Hosk was tasked to investigate

 

UnRecognized ‘Edm.Guid’ literal ‘guid’null

EDM.guid error

 

What made investigating this error more tricky, was it occured only when a new record was created.

I couldn’t seem to catch a debug message on the form onload because I think it creates new javascript files, so if you do put a breakpoint on a file it’s not used.

I did some investigation using the internet about this error

This blog had a similar error before to do with dates and json queries

 

I found this page on json fields

Edm.Guid Literal form of Edm.Guid as used in URIs formatted as a JSON string

 

I think the problem was definitely related to an Odata query and the code I was looking at used the Rest framework.

 

Fiddler to the rescue

I turned on my trusty Fiddler to try and capture what was happening.  I ran the create form, got the popup error and then in Fiddler logs I could see last line had a nasty red triangle with an exclamation in it.

I found the Odata query and could see it the filter in the oData statement was null, which meant it was trying to retrieve some a single record but was passing a null guid.

filter=field%20eq%20guid’null’

I searched the F12 debugger using the select statement to find where the code was.

The code was actually being triggered from by a ribbon button and the evaluate javascript.

 

Debugging a ribbon

Debugging a ribbon can be a little bit tricky because you can’t use the F12 debugging method and you have to put in a

debugger;

when the browser hits this, it will ask you  if you want to debug the code in Visual Studio, you say yes please.

You will now be able to step through the code to find out the problem.

Here is the code (changed to make it generic)

 

if (selectedId == null)
selectedId = Xrm.Page.data.entity.getId();

if (typeof selectedId == "object" && selectedId != null)
selectedId = selectedId [0]. id;

var fieldResults= NttDataUk.Functions.Rest.retrieveMultipleSync("contactSet",
"first name,last name,statuscode",
"contactId eq guid'" + selectedId + "'");
if (fieldResults== null) {
return false;
}

 

So the problem was it was getting the guid of the record but new products don’t have guids because the guid is only created when the new record is saved.

The actual error was being generated by the Odata query which tried to get a record using a guid = null.

Solution

There are two solutions to this problem.

Change the display rule for the ribbon button to only display for records in a form state which doesn’t equal create

display rule ribbon

The other solution was I could add in check in the Javascript, to add a check to see if selectedId == null then return false, this would show but not enable the button.

The advantages of not displaying the button would also save a little bit of time drawing the button.  You should consider I changed the display rule and not the enable rule because I felt there wasn’t any point in showing a button you can’t use.

 

CRM 2011 – Things learnt when reviewing Javascript code on form loads

It has been a school day today (hence the Grange Hill image)

 

I have been reviewing some Javascript code to see if it can be optimized.

It can be tricky understanding someone elses code, particularly when the there are 12 javascript files loaded in the form and the code is jumping about everywhere, so it can take you time just to work out where to start and the code flow before you can start to think about speeding it up.

Another important fact, which is possibly more mental but I’m not sure what the form or code is doing which makes the code have an abstract feel to it.  It shouldn’t matter what the form is doing, but for some reason it does, it must be the nosey parker in all of us.  It’s easier to understand why the code is doing certain things when you understand what the form should do and why certain fields are important.

 

Waiting for all the scripts to load

The code was initially confusing is because the initial load script, called a bunch of other scripts and waited until they were all loaded.  WHY?

To give you some background, the CRM release was CRM 2011 patch 12.

Microsoft tried to speed load times up by loading all the javascript files asynchronously (e.g. load them all at the same time).  This caused a bunch of problems (what were fixed in rollup 15) because CRM loaded the scripts all the at the same time but some Javascript files called methods in the Javascript files scripts which were still loading.  This would result in Javascript throwing an error because it couldn’t find the function.

So if you had scripts A, B, C.

Javascript file C could load first and start running, but in this script it calls a function from Javascript A, because javascript A is still loading this function call fails.  Oops.

 

Amusingly someone explained this to me by saying do you remember the great javascript async cockup of patch 12.

 

ERM no, that passed me by, please explain was my answer

 

CRM MVP Scott Durow has written an excellent blog post on how to write some javascript which waits until all the other javascript files are loaded

http://www.develop1.net/public/post/Asynchronous-loading-of-JavaScript-Web-Resources-after-U12POLARIS.aspx

 

So now I understood why the code was waiting for all the scripts to load.  When you first come across methods for a first time, you wonder if this is a new best practice or something I should have been doing, why hadn’t I seen this code before?

In the form onload, it passes in a comma seperated list of scripts to load and the last one is the script and function loaded when all the scripts are loaded.

 

Aha I had my place to start.

 

OData code with no return value

In the code I found lots of OData calls which returned no value, puzzling I thought.

It was because the code was using OData to update CRM values but why it was doing it in the form load seemed rather odd.

 

I have never used OData to write values to CRM, why was this I wonder.  Thinking about it, I guess I would usually update related entities or even the main entity with a plugin so it didn’t effect form performance.

 

here is an example of an odata update

http://rajeevpentyala.wordpress.com/2012/02/05/update-record-using-odata-and-jquery-in-crm-2011/

 

and another one

http://msdn.microsoft.com/en-us/library/gg309549.aspx

 

This code was particularly puzzling because it was updating values on the form onload?  It turned out a bit of code re use from selecting an item in the grid, was also being triggered on a grid onload.  So it was updating some values for every item in the grid.

This was an excellent place to start but I had to work out what I could remove without losing any functionality.

 

Fiddler Investigation

I had find the quick wins on performance, to weasel out the worst culprits for slow form load I used fiddler to see investigate the OData calls (which there were many)

Which OData calls took the longest

Find OData calls which were not filtered

Find OData calls which were retrieving the same data multiple times

 

I was also on the lookout for cases of inefficient coding, but most of the time was spent on odata calls, so that was my main focus.

Getting Started with Fiddler and CRM

I was having to look at performance issue of Javascript today, so I downloaded the trusty fielder2 to help me.  If you are like me, you will have heard of fiddler but may not have had reason/time to use it.

I view fiddler as big tool in your toolbox.  The kind of weapon you save for the end of level baddie.

Most of the time you don’t need to use it, although it wouldn’t hurt.  Usually I use fiddler if something isn’t working properly or there are some performance issues.

 

What does fiddler do?

Fiddler is used for Web Debbugging.  Next question what is web debugging?  When you have installed Fiddler and started it, it will then show you all the HTTP/HTTPS calls to and from your internet browsers (IE, Chrome, Firefox, etc).  This enables you to see all the traffic going to and from your computer.

This can be interesting to see what calls your Chrome extensions are making all the time.  Not only can you see they are making calls out to websites/services but you can see/inspect what data they are passing and what is being returned.

 

What is Fiddler used for

There are number of things you can use fiddler and the fiddler website has a good summary

fiddler 00

Recently I have used fiddler for performance testing.  I used fiddler to look at what OData and WCF calls were being made from a form load in CRM and seeing the performance of these calls.  I used fiddler to optimize slow calls and work out where I could combine/cache some Odata calls to reduce the number of them.

I also used fiddler to see what data was being passed and received to a WCF service to try and work out why it wasn’t working.

 

Getting Started with Fiddler

The first thing you need to do is download fiddler (actually fiddler 2), you can find it by going to the link below.  The great news is Fiddler is freeware.

http://www.telerik.com/download/fiddler/fiddler2

 

Easy tutorial and overview

http://www.asjava.com/tools/fiddler-tutorial-how-to-use-fiddler/

 

There is also a very good set of article on telerik (creators of fiddler) called, Getting Started with Fiddler

http://docs.telerik.com/fiddler/Configure-Fiddler/Tasks/ConfigureFiddler

 

One more general introduction/tutorial

http://www.mehdi-khalili.com/fiddler-in-action/part-1

 

Fiddler and CRM

If you are new to Fiddler and want to use it with CRM, then your first stop should be the excellent tutorial written by CRM MVP Scott Durow.  This is a link to part 1 but it has 4 parts and is excellent and it’s super hero themed, awesome

http://develop1.net/public/post/Fiddler2-The-tool-that-gives-you-Superpowers-Part-1.aspx

Scott’s tutorial is excellent but I will add a few screens

Hosk’s Very quick start

 

Open fiddler and you will see this screen, it will start showing all the HTTP traffic action from the browsers you have open.  If you have a few tabs open it will probably be quite busy

fiddler 01

you will see fiddler will start to track all http traffic coming in and out of your computer, which can be interesting to see what those plugins and extensions are doing

 

Pick your target

You probably don’t want to see all the traffic so I use the Any Process button which is a cross hair.

Press the button and hold, the the cross now says pick a target, which is cool because you feel like a secret agent.

Don’t forget to hold onto the mouse button (I know you did just a single click, so go back and do it again properly) then drag the cursor to your CRM browser.  Interestly I have found if I use IE it filters to only that IE page but if I choose chrome I still get the other traffic from the other tabs, so I usually use IE when I am using fiddler.

 

What this does is only capture the http data going to and from that particular Internet browser.

 

I then usually click the X and choose remove all the previously logged data.  Now reload the form/target  you want to track and you will see only the http traffic generated.

Left Window general – right window stats and detailed information on a selected row

 

CRM online

If you want capture traffic from a CRM online version then you need to capture https data

 

http://docs.telerik.com/fiddler/configure-fiddler/tasks/decrypthttps

 

The reason this is different is because (I think) it has to decrypt the https packages

 

Tools –> Fiddler Options –> HTTPS tab

fiddler 02

shows fiddler 01-02 on how to set it up

fiddler 03

Now you can see all the traffic.  Go to Contact, choose the target and then load the page.  You will see all the web traffic for the contact form.

fiddler 04

If you select one (or more) rows you can then view the data for those row(s) in the right menu.  This can enable you to view timeline (e.g. how long it took), statistics will show you information like bytes received and sent, clock duration.

If you open the contact form you will see the line

GET /services/v1/geocodeservice/geocodeservice.asmx/Geocode?query=%227165%20Brock%20Lane%0DRenton%2C%20WA%2061795%0DU.S.%22&mapBounds=%2260.239811169998916%2C

I believe this is getting information for the map on the form.

I click on the row, went to inspector and you can then view all the details of the soap message

fiddler 05

There are lots of other great things you can do with fiddler, which are covered in Scott Durow’s excellent blog series, so if you want to use fiddler with CRM then you should start there.

 

Other CRM and Fiddler blogs

http://mscrm-njl.blogspot.de/2013/06/how-to-use-fiddler-to-debug-crm-2011.html

http://blog.sonomapartners.com/2012/01/fiddling-with-crm.html

 

http://woodsworkblog.wordpress.com/2013/11/07/crm-2013-diagnosing-access-is-denied-using-fiddler/

Hosk’s CRM 2015 highlights

Here is a screen shot of the new organizational hierarchy (taken from the excellent top ten feature article)

Microsoft’s naming convention of using years in the product name can be very confusing.

I have often thought this year was 2013 because I talk about CRM 2013 all the time.

The code names are totally forgettable, Vega? They seem to be designed only to add more confusion when I haven’t got a clue what version people are talking about.

Talking about Microsoft, I recently wrote a couple of articles which you may find interesting on LinkedIn

How will Microsoft Social Media sell

Are people beginning to like Microsoft again?

 

If you want to read the full release guide (I wouldn’t be writing this blog post if I really thought you did) you can find it here

Release Preview Guide

 

Hosky Highlights of CRM 2015 enhancements

The first piece of good news is the release is for both versions of CRM (online and on-premise).  This is good news for developers/consultants and customers.

Looking at the highlights Microsoft seemed to have really focused on delivering some of the enhancements people have been asking for and I think it’s great Microsoft are listening to the Microsoft Dynamics Community.  I would also say some of the new features are really completing the features they added in CRM 2013.  CRM is always moving onwards and upwards.

I thought I would have a look at the CRM 2015 highlights from a developer/consultant view e.g. how will it effect the solutions we are creating.

 

 

Field Level security for out of the box fields

Finally at last, this has been top of the Microsoft Connect enhancments for at least 10 years.  You can now add field level security to standard CRM fields

 
Business process are improved

There is a new Client API for business process flows,  you will programatically be able to access

Active and enabled processes

 

Calculated fields

Calculated field (e.g. Doing sums), nice

Rollup fields

 Improved Conditions operators
Queries using the advanced find can often be tricky to write but these new operators should make it a bit easier
Above, AboveOrEqual, UnderOrEqual, Under, Not Under
You can read more about it here
 
Business rules

Will have support for IF/Else if/else, which means you won’t have to create twice as many business rules as you need

Business rules will also enable you to group them

it says something about setting default values, which would be very useful because this used to be done with Javascript.

Improvements to the business rule editor

 

 
Server Side Synchronization Enhancements

They have continued to improve this and you can now sync attachments

Mark some in outlook as private to prevent syncing to CRM

sync appointments and tasks

Organization Hierarchy

You can view the organisation in a tree view, awesome, I have been asked for this by feature by quite a few customers over the year.

 

Search

You will be able to search different record types, yes a global search

There are lots of other features for you to find out about and you can read lots of other blogs with that information, I just wanted to write about the things I think look really good.

CRM 2015 will no longer work on

SQL Server 2008 R2 (the classic old favourite) and windows server 2008
stops support for IE 8, IE 9, which is quite significant because many companies are very slow and upgrading internet explorer, I’m not sure why
There are lots of other good blogs about the new features but this one was probably the best
 
 

 http://www.crmboys.com/microsoft-dynamics-crm-2015-vega-%E0%A4%B5%E0%A5%87%E0%A4%97/

 

 

 

 

WCF with no service xml or endpoints? What is this magic?

I had to write a WCF service for a project and I hadn’t created a WCF service for a while.

I was trying to write mine to fit in with the rest of the projects but I was totally confused because I was looking at the other WCF services in the project and looking to copy the shell and modify (like all good developers do:-))

I could see there was a SVC file, I could see the code but in the web.config there was no service xml section for the WCF service.

I trying to look at the url for the SVC to see if I could see the wsdl but when I did I got the message no endpoint found.

no endpoint found

 

WHAT WAS GOING ON.

Sometimes as a developer, when you haven’t worked on an area for a while, you have a horrible feeling they have changed the way it worked to some completely new method and framework a bit like the way web services were replaced with WCF.   but this wasn’t the case, it was CRM 2011 project (not that makes any difference calling a WCF service).

The most puzzling aspect was the WCF code was being called (I called it myself to make sure it worked) from a Javascript form.

I asked a developer and he said it must be a factory service, I must have had a completely blank look on my face because he then offered to show me.  A good tip is if you don’t understand something ask someone to point you in the right direction because you can save yourself days of puzzling.

He said right click on the SVC file in Visual Studio and choose View Markup
 
You will see this
mine was like this
<%@ ServiceHost Language=”C#” Debug =”true” Service=”Hosk.HoskRibbonService” CodeBehind=”HoskRibbonService.svc.cs %>
he said change it to this
<%@ ServiceHost Language=”C#” Debug =”true” Service=”Hosk.HoskRibbonService”  Factory=”System.ServiceModel.Activation.WebServiceHostFactory” %>

I removed the service xml section in the web.config and then as if by magic it worked and I was able to call the wcf service using jsonp call (cross domain) in javascript.

Not only had I never heard of using WebServiceHostFactory to create a WCF but I had never come across it in any of the code I have worked with.

I was interested to learn a bit more about it,  It’s a way to dynamically create services and it automatically creates the endpoints for the service and was added in .NET 3.5

 

Here is MSDN class

http://msdn.microsoft.com/en-us/library/system.servicemodel.activation.webservicehostfactory(v=vs.110).aspx

 

this flashcard gives a good quick explanation

http://www.brainthud.com/cards/5218/25206/what-is-the-purpose-of-the-webservicehostfactory-class-and-how-is-it-used

Question

What is the purpose of the WebServiceHostFactory class and how is it used?
Answer

When hosting a web service in IIS, the WebServiceHostFactory class can be used to automatically configure the endpoints for the service. Endpoints will be configured to use WebHttpBinding and WebHttpBehavior. The WebServiceHostFactory class will automatically create a WebServiceHost class when the web service is activated. The following example demonstrates how to reference the WebServiceHostFactory in a .svc file:

<%@ ServiceHost 
    Service="OrderService" 
    Factory="System.ServiceModel.Activation.WebServiceHostFactory" %>

 

 

Here are some simple tutorials if you want to learn more

http://dotnet.dzone.com/articles/creating-restful-wcf-service

http://agilewarrior.wordpress.com/2010/12/19/how-to-create-a-simple-wcf-rest-service/

http://www.c-sharpcorner.com/uploadfile/dhananjaycoder/rest-eanbaled-service-in-wcf-tutorial/

 

Picture from http://daarken.com/blog/2012/08/11/lotr-magic-and-other-news/