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.

 

Advertisements

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/