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!

Updated 3-27-2012
The config now supports multi-forms and allows for including only specific attributes, sections, tabs or left navs. Below is an example of specifying which form to use (FormName) and specific attributes, sections, tabs, and left navs to generate for.

Set IncludeAllAttributes, IncludeAllTabs, IncludeAllSections, and IncludeAllLeftNavs respectively to false to only include certain ones otherwise set it to true to include everything.

<?xml version="1.0" encoding="utf-8" ?>
<JsConfig CrmServer="http://server/org"
<Entity EntityName="appointment" FileName="appointment.js" FormName="Information"
<Attribute Id="salutation" />
<Attribute Id="firstname" />
<Attribute Id="lastname" />
<Section Id="Address" />
<Tab Id="General" />
<LeftNav Id="navAddresses" />

Last edited Mar 27, 2012 at 7:55 PM by bscarlavai, version 5


No comments yet.