Tuesday, February 14, 2012

IE Developer Tools

I use the IE Developer Tools (or IE Dev Toolbar) almost every day.  I was going to write a post about how to use it but I just discovered today that MSDN already has some great documentation around it.

Here's a good starting point with "Discovering Internet Explorer Developer Tools" - http://msdn.microsoft.com/en-us/library/dd565628(v=vs.85).aspx

I would also dive into this article "Debugging Script with the Developer Tools" - http://msdn.microsoft.com/en-us/library/dd565625(v=vs.85).aspx.  One of the most common issues asked on the CRM forums are javascript errors.  Debugging with the dev toolbar can help solve a lot of those issues.

Another great feature of the dev toolbar is Profiling javascript which this article talks about in depth - http://msdn.microsoft.com/en-us/library/dd565629(v=vs.85).aspx.  This helps analyze the performance of your javascript and since we write a lot of javascript for CRM it can help optimize your form loading experience.

Sunday, February 12, 2012

CRM 2011 Development Resources

The Development Resources section of the CRM Wiki is really coming along!  There are some extremely helpful tools out there to help expedite your CRM development.

Check it out! http://social.technet.microsoft.com/wiki/contents/articles/2490.microsoft-dynamics-crm-2011-development-resources.aspx

Friday, February 10, 2012

Pre-Delete Plugin 'Gotcha'

If you are running a plugin on the pre-operation event of the Delete message, one thing to note is that by that time CRM has already disassociated the record in context with any child records.  Therefore if you need to query for any child records relating to that record, nothing will return from your query.

A way around this would be to register your plugin in the pre-validation event.

Example query that won't return any results in pre-operation Delete of 'recurringappointmentmaster':

Friday, February 3, 2012

CRM 2011 JavaScript Model Generator

I am happy to announce the CRM 2011 JavaScript Model Generator!  This tool will increase developer productivity as well as performance in regards to client-side scripting on CRM 2011 entity forms.

The JS Model Generator will go and grab the Form XML for specified entities and create objects for each attribute, tab, section, and left navigation item that currently exists on the published Main form.  This allows you to use intellisense to see which attributes, tabs, sections, left navigation items exist on the form and also provides easier syntax than using Xrm.Page.  It will generate all this javascript inside an existing javascript file (on the developer's machine, not a CRM web resource).


Form is the base object for referencing the tabs, attributes, sections, and left nav items.  Use Form.Attributes for Attributes, Form.Tabs for Tabs, Form.Sections for Sections and Form.Navigation for Left Nav Items.

The syntax below is the same for each type but one difference is that Form.Attributes.<fieldname> will give you both Attribute and Control objects whereas the other types will give you only their respective type (Xrm Tab, Section, Nav item object).

Form.Attributes. – This will give you intellisense and show you all the attributes that exist on the form currently

Form.Attributes.<fieldname> - This will give you BOTH the Xrm.Page.getAttribute(‘fieldname’) AND Xrm.Page.getControl(‘fieldname’) objects combined into one object (notice you can use both setValue and setVisible below)


Form.Attributes.<fieldname>.exists() - This will return a boolean telling whether the field exists on the form or not (in case the generated model is out of date)

Form.Attributes.Ids. – This will list the same thing as .Attributes but gives you a reference to the string value of the Id instead of the attribute/control object

How to generate it: 

NOTE – Make sure your javascript file changes are saved before generating the model as your unsaved changes will get overwritten.
  1. Edit the provided sample.jsconfig file.
  2. Update CrmServer to use the correct server and org.  
  3. Set the JsDirectory to be the folder where your script files are located.
  4. Add an Entity node for the entity form that you will be working on
    • EntityName is required and needs to be the schema name
    • FileName is optional and it will try to use the EntityName + “.js” to find the javascript file in the JsDirectory.  Use this if the file name is different than the EntityName
  5. Run the JSModelGenerator.exe

<JsConfig CrmServer="http://server/org"
    <Entity EntityName="contact" FileName="contact.js" />

Now in your javascript file there should be some generated code at the bottom and you can begin using the new model objects!

An added benefit of using Form.Attributes.<fieldname> is that the first time you call a method on the object, it will cache the respective XRM object behind the scenes to optimize performance.

Wednesday, February 1, 2012

Tab Performance - CRM 4.0 vs CRM 2011

Tabs in CRM 4.0 are more like your traditional tabs you see on most web sites.

The nice thing about these style of tabs in CRM 4.0 are that only the content in the selected tab loads when the form loads.  This saves time on the initial hit and it won't load custom pages on other tabs until those tabs are selected.

On the other hand in CRM 2011 the tabs are vertical instead of horizontal.

The issue with vertical tabs is that by default everything loads initially when the form loads.  This includes all Silverlight resources that are on the form.  Also if you have Javascript that hides and shows fields on the form then potentially you could see the form jump around onload.  

In CRM 2011 we can easily get the same performance advantages of CRM 4.0 tabs.  To do this just simply uncheck the tab setting "Expand this tab by default".

By not expanding the tab by default, Silverlight won't load until the tab is clicked so we can get the "on demand" loading like CRM 4.0.  Also if we have Javascript hiding/showing fields on tabs other than the main one then we won't see the form jumping around on those tabs that are collapsed onload.

Hope this helps!