The Situation

 

I'm not sure when it happened. I was happily going along, doing some configuration work for a new Dynamics CRM 2013 on premise client, when my test users began experiencing an on_load error when opening contact records.  I had hardly done anything on the contact record... well, full disclosure, I had dabbled in a little JavaScript. I am not a JavaScript master, more a copy - paste, try to bend it to my whim, sometimes successful dabbler. So I figured I had tweaked something a bit too far and was getting pay back in the form of an error. When I reviewed the two scripts I had on the contact record, I realized I didn't have an on_load script on the contact form. So I disabled my JavaScript, but still got the on load error. What the heck?!!

 

 

 


The Search

 

So off to my favorite search engine where I finally found a few posts, shockingly few, related to the error I was seeing. Apparently there is a bug that presents sometimes, either in upgraded organizations or in new 2013 organizations when you import a managed solution. This causes a Microsoft out of the box script to get attached to the on_load event, as if a user had attached it to the form in the user interface as shown here:

 

 

 


Attempted Solutions without Success


I tried finding the script that the form seemed to be looking for, using some of my hard won F12 skills, and I was successful! But creating a web resource, adding it to the form, pasting in the script, calling the function on_load, and adding it to the on_load event did not placate the contact form - the error continued taunting me. Next I tried creating a solution with the contact entity, exporting it and looking for the area mentioned in the posts I found, but to be honest I was having trouble following the post, I needed a few more pictures! Next I exported the contact entity from a fresh, untouched organization and compared it to the contact entity from the organization where the error was occurring. I recognized some things but not enough to make any educated guesses as to a fix. So, I let it rest for a bit.

 

The Solution


Fast forward to this week. I finally had time to take a breath and give Microsoft a call. Once I gave them the play-by-play of my situation, my research and my attempts to fix the issue, they matched me up with a great technician. After reading all the info I had provided, the technician had an easy fix option, as well as a long, drawn out option. I'll take door number one please Alec! We created a new solution, added the contact entity only, exported, extracted, opened with Notepad++ and went on the search for InternalHandler nodes. We found about four nodes with InternalHandler and number three was the problem child. Somehow the Microsoft script had gotten associated with on_load.

 

This is an example of one that is fine:

<event name="setadditionalparams" application="true" active="true">

                                    <InternalHandlers>

                                      <Handler functionName="Mscrm.parentcustomerid_setadditionalparams" libraryName="Contact_main_system_library.js" handlerUniqueId="76092dad-XXXX-XXXX-8e60-db497b408601" enabled="true" passExecutionContext="true" />

                                    </InternalHandlers>

                                  </event>

 

This was our problem child…

<events>

                <event name="onload" application="true" active="true">

                 <InternalHandlers>

                    <Handler functionName="Mscrm.ContactMainSystemLibraryWebResource.form_onload" libraryName="Contact_main_system_library.js" handlerUniqueId="4ea24ebd-XXXX-XXXX-6812c3867b54" enabled="true" />

                  </InternalHandlers>

                  <Handlers>

                    <Handler handlerUniqueId="{96e5b9aa-b069-019e-07c9-de4e35ac4e01}" functionName="onLoad" libraryName="c5_ContactForm" enabled="true" passExecutionContext="false" parameters="" />

                  </Handlers>

                </event>

 

Notice the event name="onload" and then the InternalHandlers node. The internal handlers node is the one that is not supposed to be there. Now the Handlers node is supposed to be there, it is a script I added to show how a web resource will look if attached through the user interface to the on_load event. 

 

All we had to do was comment out the InternalHandlers node, zip back up the files, import and publish.

           <!--  <InternalHandlers>

                    <Handler functionName="Mscrm.ContactMainSystemLibraryWebResource.form_onload" libraryName="Contact_main_system_library.js" handlerUniqueId="4ea24ebd-XXXX-XXXX-6812c3867b54" enabled="true" />

                  </InternalHandlers>  -->

 

If you have commented correctly, only the InternalHandlers node will be green when looking at it in NotePad++. You may wonder, why not just delete it? Not a good idea. Deleting the code presents a bigger chance for error. This way, if you comment out too much or not enough, all you have to do is remove/update the comment to remedy the "too much" or "too little", rather than trying to scramble to find that piece of code you just obliterated.

 

Once we made this change, the contact record loaded without incident and the Microsoft tech and I decided this had made our weekend. Hope this will make your weekend as well!

 

For more information about this blog or C5 Insight, please contact us here!