Monthly Archives: February 2012

4Feb

XRM 2011 JavaScript: Another 101 Lesson in Microsoft Dynamics CRM 2011

When you’re learning JavaScript, you’ll often come across the need to do something to every field on the form.  When you do, it’s important to have efficient code to make such widespread changes so the user doesn’t have to wait for the JavaScript to finish.  This lesson consists of several parts, some of which you’ll probably already know but hopefully there are some things in here for everyone.

Setting up our Environment

First thing first, open your CRM 2011 development environment and browse to an account form.  Once the account form is open, hit F12 on your keyboard.  A window should popup that looks like this:

image

If instead, you see the window in the bottom of your browser page.  Click the little “Unpin” button shown here:

image

 

This is IE Developer Tools and if you haven’t used this in the past, then I hope you enjoy not having to save/publish/refresh/test nearly as often.  To start, we’re going to see how many fields we have on the form.  When inside of the CRM form, we’d use something like:

Xrm.Page.data.entity.attributes.getLength()

But when we’re inside Developer Tools, we actually have a different context.  So we need to click on the “Console” tab and execute:

frames[0].Xrm.Page.data.entity.attributes.getLength()

image

 

Anything we want to execute on the form, we can do by simply prepending “frames[0].” in Developer Tools to get the proper context.  This allows us to write and test code instantaneously, which is a huge timesaver.

Read More »

© Copyright 2012-2014, All Rights Reserved