Knowledge found and lost while working with Microsoft Dynamics CRM
RSS icon Home icon
  • Including custom JavaScript files in MSCRM 3.0

    Posted on February 18th, 2006 mitch Print Print 7 comments

    The more you get into MSCRM development, the more you will probably realize that you are writing quite a bit of JavaScript to control various aspects of the CRM Client experience.  As most programmers find, the more code you write, the more you write code.  You also start developing a code library containing your most often used functions so that you don't have to rewrite them each time you need them.

    In most programming languages, the concept of an Include File exists. Include files are usually referenced at the beginning of your source code file and are merely instructions to your compiler, interpreter, or whatever, to include the contents of that file within your program. 

    This allows you to create a library of related sub-routines or functions that can be referenced from any number of other programs. Since you only have one copy of those routines, it cuts down on your maintenance requirements.

    So how does any of this relate to MSCRM?

    MSCRM version 3.0 gives you the ability to peform actions when the value of a form field changes – the OnChange Event.  This allows you to take action whenever a user changes a particular form.  Take a look at this example:

    The OnChange events for both Price and Quantity contain the following JavaScript code to automatically add the two fields together:

    crmForm.all.new_total.DataValue=
    crmForm.all.new_price.DataValue*
    crmForm.all.new_quantity.DataValue 

    This is really not very much code and there are really only two fields involved so it's pretty easy to maintain.  But, what happens if you have five or ten fields to calculate. That really becomes work at that point, and it can create a maintenance nightmare as well.

    You can solve this problem by putting the above JavaScript into a file on disk and include that file in the Form's OnLoad event.  Here's how it will work:

     

    Create the .js file:

    Open Notepad and copy the following Javascript into it

    function OrderFormAdd()
    {
       crmForm.all.new_total.DataValue=
       crmForm.all.new_price.DataValue*
       crmForm.all.new_quantity.DataValue 
    }

    Save this file as myfunctions.js and place it in a directory below your MSCRM web directory called myscripts.

     

    Reference your .js file:

    In the OnLoad event of your Form, include the following code: 

    var script = document.createElement('script');
    script.language = 'javascript';
    script.src = '/myscripts/myfunctions.js';
    document.getElementsByTagName('head')[0].appendChild(script);

     

    Update the OnChange Events:

    Now we need to update the OnChange events for the Price and Quantity fields. Remove the existing JavaScript and replace it with the following:

    OrderFormAdd();

     

    Save and publish your form and you are done.  From now on, any time you need to modify the calculation on the Order Form, just edit the myfunctions.js file. No additional work needs to be done to the CRM Form.

    Note:

    • If you make a change to the .js file and you don't see the change take effect, delete your browser's temporary Internet files and try it again. The client can cache the .js and it will be using the older copy instead of the newly updated master copy.

     

    Using Included Functions in the Form OnLoad Event:

    It was pointed out by "Alex" who wrote the actual JavaScript include code that it is possible to run into a timing issue because the include file has not yet finished appending to the CRM Form.  This is really only a problem if you need to access a function from your include file from within the OnLoad event.

    To circumvent this issue, we need to wait for the script's state to change to "loaded" before any functions in the include file can be accessed:

    var script = document.createElement('script');
    script.language = 'javascript';
    script.src = '/myscripts/myfunctions.js';
    document.getElementsByTagName('head')[0].appendChild(script);

    var f = function()
    {
      if (event.srcElement.readyState == "loaded")
       SomeFunction(); // some function from MyFunctions.js
    }

    script.attachEvent("onreadystatechange", f);

     

    Additional Notes:

    This solution will not work if you have the CRM 3.0 Outlook Laptop Client deployed. This is because the Laptop client utilizes a local Web server and if physically disconnected from the main CRM web server, the JavaScript file will be unavailable and a script error on the page will result.

    In addition, since the JavaScript file is not actually part of the CRM system, it is not replicated to the Laptop client during syncronization.

    Michaeljon Miller has a post discussing CRM SDK access while offline.

     

    References:

    The JavaScript code for this article was taken from a newsgroup conversation between Ronald Lemmen and "Alex."  Please consult the original thread for context.

    CRM Developer Newsgroup Post

    Using the CRM SDK offline

     

    Customization, Dynamics CRM, Unsupported
    1 Star2 Stars3 Stars4 Stars5 Stars (2 votes, average: 4.50 out of 5)
    Loading ... Loading ...
    8,682 views
  • Emoticons: the next generation

    Posted on February 18th, 2006 mitch Print Print No comments

    Ok, this is not something that my Mom would like nor understand, but most people will think it's funny.

    Assicons

     

     

    Meanderings
    1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
    Loading ... Loading ...
    789 views
  • Many to Many in Microsoft CRM 3.0

    Posted on February 18th, 2006 mitch Print Print No comments

    Ben Vollmer has written an excellent article describing how to create a pseudo many-to-many relationship within MSCRM 3.0.

    In case you didn't know, MSCRM 3.0 doesn't natively support many-to-many, or one-to-one relationships and as Ben states: it's "One of the things that has driven a few newer partners who are used to other CRM Systems bonkers…"

    Check out Ben's article should you need to create a many-to-many relationship.

    Customization, Dynamics CRM
    1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
    Loading ... Loading ...
    1,757 views
  • A watch that even I would like to own

    Posted on February 18th, 2006 mitch Print Print No comments

    [via OhGizmo ]

    I'm really not a techno-geek like a lot of my friends, but this watch is pretty cool: 

    Taluswatch

    It's called the Talus Abouttime.  They also have a watch called the Talus Timeline, but I don't think it's nearly as cool as Abouttime.

    Visit The Talus Watches for a demo.

     

    Misc
    1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
    Loading ... Loading ...
    1,691 views
  • MSCRM 3.0 Address Record Longitude and Latitude

    Posted on February 16th, 2006 mitch Print Print No comments

    In case you've never looked, the various CRM Entities that contain address information also have Attributes for Longitude and Latitude, though they are not generally shown on the data entry forms.

    This evening, I was doing some research regarding populating those Attributes for Marketing Searches when I noticed a problem:

    They have a minimum value of 0 and a maximum value of 1,000,000,000.00.

    Why is this a problem, you ask? Well, mostly because of the following:

    • Longitude values must be from -180 to 180 degrees
    • Latitude values must be from -90 to 90 degrees

    This means that users will not be able to input data for some parts of the planet.

    To correct the problem, edit each attribute and reset the minimum and maximum values to those listed above.

     

    Customization, Dynamics CRM
    1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
    Loading ... Loading ...
    833 views
  • Changing Label Attributes on a MSCRM 3.0 Form

    Posted on February 16th, 2006 mitch Print Print 1 comment

    The labels for data entry fields on CRM 3.0 forms can normally only be set to the following values: Normal, Hidden, or Disabled.  Not a whole lot of functionality there should you wish to get inventive ( or at least, more descriptive ) with your forms.

    Using a bit of JavaScript in the Form's OnLoad event, you can alter the labels in a variety of ways.

     

    Changing the Weight of the font ( how dark it is ): 

    crmForm.all.[field name]_c.style.fontWeight = 'bold';

    Possible values:

    normal, bold, bolder, lighter, 100, 200, 300, 400, 500, 600, 700, 800, 900

     

    Changing the Font Style: 

    crmForm.all.[field name]_c.style.fontStyle = 'italic';

    Possible Values:

    normal, italic, oblique

     

    Changing the Background Color: 

    crmForm.all.[field name]_c.style.backgroundColor = 'green';

    Possible Values:

    Named or value color

     

    Changing the Font Color: 

    crmForm.all.[field name]_c.style.color = 'green';

    Possible Values:

    Named or value color

     

    Other style elements do exist, but to keep in mind that your changes do not need to vary the CRM user experience too much.

     

    References:

    Javascript style attributes

    Hiding a Form Field Label in MSCRM 3.0

    CRM 3.0 UI Style Guide

     

     

    Customization, Dynamics CRM
    1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
    Loading ... Loading ...
    1,331 views
  • Hiding a Form Field Label in MSCRM 3.0

    Posted on February 12th, 2006 mitch Print Print 2 comments

    As you know, CRM automatically adds a field label/description to any field on the data entry form ( as shown below ): 

    Normal text field edit box

    Occasionally, I have run into the requirement to hide the field label.  This is easily done by unchecking the Display label on the form property of the field:

    Normal text field edit box 

    Unfortunately, this produces what I think is an undesirable result:

    Want I really want is to have the actual edit field to remain where it was originally, lined up with the other edit fields.  So, how do we get around this functionality?  With a little ingenuity and JavaScript, of course.

    Add the following line to the Form's OnLoad event:

    crmForm.all.[fieldname]_c.style.color = "#EEF0F6";

    All field labels are named exactly like the data entry fields, but with a "_c" appended to the end of the name.

    In this example, we are changing the color of the text of the field label to match the Form's background color. This will, in effect, "hide" the label from the user, while keeping the form layout the same.  Here is how it will actually look:

    Pretty cool, huh? 

    NOTE: I found the color information used in this example by reviewing the sample stylesheet that is included with the CRM 3.0 SDK.

     

    Update (2/18/06):

    Ryan Farley has a great article that shows a similar technique for hiding an entire field.

    Customization, Dynamics CRM
    1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
    Loading ... Loading ...
    4,571 views
  • Improper Thought of the Day

    Posted on February 12th, 2006 mitch Print Print No comments

    So I'm making meat balls in Marinara sauce for lunch.  As I'm loading up the Crock Pot with frozen meat balls and sauce, the following thought pops into my head:

    Man, you could put someone's eye out with one of these.

    I honestly have no idea how I come up with these things sometimes…

     

    Meanderings
    1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
    Loading ... Loading ...
    750 views
  • Documenting your MSCRM 3.0 Schema

    Posted on February 11th, 2006 mitch Print Print 7 comments

    MSCRM 3.0 ships with a really cool web page that allows you to view the current CRM system schema. If you browse to the following location:

    http://[your crm server]/sdk/list.aspx

    You will receive a list of all of the entities within the current CRM system.

    Clicking on the Definition icon ( little yellow box ), will show a web page containing a complete overview of just about everything you need to know about that Entity: Type information, Attributes, and Relationships.

    Copy that page, paste it into an Excel worksheet, and you have fully documented most of the information about that Entity.

    Caveats:

    • The List doesn't show you any JavaScript Event information ( OnLoad, OnSave, OnChange ).
    • The Entities are listed by their Schema name so if you've renamed system entities, you will find them listed under their original name.
    • Custom entities are listed by their Schema name as well: new_entityname. ( Assuming you haven't altered the custom prefix. )

    I think the thing I like the most about this feature is that it let's me see the Entity layout in a quick, at-a-glance, view without having to resort to SQL Enterprise Manager or SQL Query Analyzer.  This is very useful when you are creating several related Entities that need to have similar or exact table structures.

     

    Customization, Dynamics CRM
    1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
    Loading ... Loading ...
    11,096 views
  • Resetting the Tab Order on MSCRM 3.0 Forms

    Posted on February 10th, 2006 mitch Print Print 1 comment

    Do people still use keyboards in this day and age of graphical user interfaces and mice?  You be they do!  After all, it's really hard to type with a mouse and removing your hand from the keyboard to move and click the mouse button actually lowers productivity.

    So, if you use the keyboard to perform data entry while in Microsoft CRM, you have probably noticed what I consider to be a non-standard tab order implementation.

    CRM tabs from top-to-bottom, left-to-right
    ( within a section; after which it moves on to the next section ):

     Example 1: ( CRM Tab Order )

    Field1 Field3
    Field2 Field4

    Most other applications tab from left-to-right, top-to-bottom:

      Example 2: ( Normal Tab Order )

    Field1 Field2
    Field3 Field4 

     

    How the Tab Order Works 

    Each data entry field has a property called tabIndex which is a number ( integer ) that instructs the window the order in which to move the cursor between the various fields.  The order is from from lowest to highest, i.e., from 1 to 10,000, or whatever. 

    This means your first field has the lowest tabIndex value and your last field as the highest.

    Microsoft CRM appears to set the first data entry field tabIndex to 1000 and increases the tabIndex by 10 for each subsequent field. For example:

    Example 3: ( CRM Tab Order, with TabIndex Values )

    Field1: TabIndex=1000 Field3: TabIndex=1020
    Field2: TabIndex=1010 Field4: TabIndex=1030

     

    Changing the Tab Order

    In certain cases, you may wish to change the tab order so that users are not so confused by the change ( and you as the form designer are not confused as to where and how to place your fields ).  All we need is a little JavaScript code in the Form's OnLoad event, and we're set:

    crmForm.all.Field1.tabIndex = 1000;
    crmForm.all.Field3.tabIndex = 1010;
    crmForm.all.Field2.tabIndex = 1020;
    crmForm.all.Field4.tabIndex = 1030;

    Note: replace Fieldx with the schema name of the field and leave the rest as is.

    Which produces the following Tab Order:

    Example 3: ( Tab Order Reset )

    Field1: TabIndex=1000 Field3: TabIndex=1010
    Field2: TabIndex=1020 Field4: TabIndex=1030

     

    Final Notes:

    1. Setting the tabIndex to 0 will result in the field being ignored by the tab order. While you don't run into this requirement often, it is there if you need it.
    2. Setting the tabIndex values to random numbers would be:
      1. Funny ( for a little bit )
      2. Would confuse the heck out of the users
      3. Would generate support calls
      4. And probably get you fired. :)

     

     

     

    Customization, Dynamics CRM
    1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 3.00 out of 5)
    Loading ... Loading ...
    931 views