The other day I was doing an audit for one customer who reported strange behavior of Dynamics CRM. The solution was working very good in everyday scenarios but started to throw system errors when the users got more experienced. Internal Dynamics functions, no logs, no trace, nothing. Where to begin? This was not another Hercules Poirot episode, but I felt a little bit like a detective investigating a crime scene 🙂
Gathering clues
It started with a strange behavior of the Outlook plugin — certain forms wouldn’t open. Quick view in Outlook worked like charm, but when the user double-clicked on the record it was loading and loading… and loading…
Forms open in web client, you can view them in Outlook, but you cannot open them from Outlook…
Without access to trace it was difficult to deduce what was happening, but I was able to narrow down the problem to couple of entities. Most were working OK, which meant only one thing. Some customization disrupted the default behavior of built-in functions.
My second clue came sometime later when users reported another issue. Cancel button was not working on mass edit form. However, they were able to do so by pressing escape button. Strange. The issues shared almost no entity, but maybe that’s because users were using different parts of the system? I checked that out and was able to confirm, that both bugs were connected the same entities. It was obvious that some customizations were responsible.
Following footsteps
Interested what was the error message with the edit form? Here it is:Error message:
CrashReport:
FileName:/_common/global.ashx
LineNumber:4028
Function:anonymousr:Cannotreadproperty’href’ofundefined
ErrorReport:<CrmScriptErrorReport>
<ReportVersion>1.0</ReportVersion>
<ScriptErrorDetails>
<Message>Uncaught TypeError: Cannot read property ‘href’ of undefined</Message>
<Line>4028</Line>
<URL>/_common/global.ashx?ver=-1665914983</URL>
<PageURL>/_grid/cmds/dlg_bulkedit.aspx?iObjType=1&iTotal=3&dType=1</PageURL><Function>anonymousr:Cannotreadproperty’href’ofundefined</Function><FunctionRaw>TypeError: Cannot read property ‘href’ of undefined</FunctionRaw>
<CallStack><Function>anonymousr:Cannotreadproperty’href’ofundefined</Function></CallStack>
</ScriptErrorDetails>
<ClientInformation></CrmScriptErrorReport>
Global.ashx? Would it be possible that some internal functionality was broken? I investigated javascripts and it was clear. Developer who created those scripts used a series of namespaces to avoid overriding code. It looked something like this:
(function () {
if (typeof (NameSpace) === “undefined”)
{ NameSpace = { __namespace: true }; }
if (typeof (NameSpace.Example) === “undefined”)
{ NameSpace.Example = { __namespace: true }; }
if (typeof (NameSpace.Example.Entity) === “undefined”)
{ NameSpace.Example.Entity = { __namespace: true }; }(…)}
Catching the bad guy
Looks promising right? Nothing wrong with that? Well, the idea is very good if you stick to it. In this case, the developer didn’t want to write NameSpace.Example.Entity each time, so inside hew wrote:var self = NameSpace.Example.Entity;
and later on:self.FormName = { …}

How come no one noticed that? Before drawing any final conclusions I debugged the global.ashx and confirmed that the script was loaded and overrode the global.ashx window.self.
After that the fix was easy and it managed to resolve all found “strange system behaviours” that the support team couldn’t find.
Conclusion: Why wasn’t it caught during testing?
The code works for most everyday scenarios. I imagine noone tested the mass edit button (it is an OOTB functionality, so why bother?) and francly speaking I have never seen any customer testing out-of-the-box functionality on UAT sessions. Advises I may give are simple:
- Be inline with Microsoft guidelines
- Verify your code often
- Don’t forget to check OOTB functionality
- KISS — Keep it simple, stupid 😉
Keep coding 🙂