Skip to main content

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).

Usage:

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"
          JsDirectory="C:\Source\Project\Scripts">
  <Entities>
    <Entity EntityName="contact" FileName="contact.js" />
  </Entities>
</JsConfig>

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.
Enjoy!

Comments

  1. Precise is a leading brand for Model makers and engineering model makers. With our innovative ideas, excellent artisans and specialized materials.

    ReplyDelete
  2. Precise is a leading brand for Model makers and engineering model makers. With our innovative ideas, excellent artisans and specialized materials.

    ReplyDelete

Post a Comment

Popular posts from this blog

Announcing the New Dynamics 365 Toolbot Chrome Extension!

Today I am excited to announce the new Dynamics 365 Toolbot! This new Chrome Extension will allow you to perform commands that will help you with your development or administrative tasks. The extension can be found here - https://chrome.google.com/webstore/detail/dynamics-365-toolbot/kljiiminicfmdlplhejocopfmgmipach.

Note: Currently, due to the APIs being used, it only works on v9+.

First, navigate to the link above using Chrome and install the extension. Then, head to your Dynamics 365 environment and open a record. From there, click the little blue robot icon in the toolbar of Chrome which will pop open the Toolbot.



Click the text box and a list of commands will display. You can select or type any of the commands and hit Submit to execute them. Some commands require you to replace the default token with the desired request.


For example, select or type "display id" and click Submit and the Toolbot will display the current record's ID.



The majority of the commands should …

CRM 2011 LINQ - All Columns vs. Selected Columns

When creating LINQ queries in CRM 2011, it is easy enough to return the whole column set of the entity record without even thinking about the impact.  
Below is an example of querying all contacts from Chicago and returning all columns for each contact record.


This can be a big performance impact depending on the amount of columns that exist on the Contact entity and how many contact records exist in the system.  Another issue is that it could cause errors down the line if some of the attribute types are changed in the CRM system since the data is being bound to a model class that could be out-of-sync.
From the MSDN article on constructing LINQ queries (http://msdn.microsoft.com/en-us/library/gg328328.aspx), we can see that the select clause creates a column set:
The select clause defines the form of the data returned. The clause creates a column set based on the query expression results. You can also define an instance of a new object to work with. The newly created object using the…

Dynamics 365 ToolBot: Auto-populate the form

Today I released a new command for the Dynamics 365 ToolBot that I am really excited about! If you're not sure what the Dynamics 365 ToolBot is, it is a new Chrome extension that I released recently that allows you to quickly execute helpful commands for administrators, developers and testers.

This new command, called "Fill Form", will automatically populate all the fields on the form with random data. As a developer, I always need test data and I am the worst at coming up with fake data to use. With this command, you can navigate to any record, open the ToolBot, type "Fill Form" and your record will instantly be populated with random data so you can quickly save the record and proceed with your testing.


A few things to note about this command:
It attempts to detect contact fields (based on the field name) such as first name, last name, email, phone and address and populate those fields with realistic fake dataAny other field will generate random data based on t…