How to get the Entity Type Code via the Metadata Webservice in JavaScript

January 25, 2011 by · 3 Comments 

Sometimes you want to fill in a default value in a lookup field. In order to do so you need to specify the Id, Value and Object Type Code, also known as Entity Type Code, of the entity (for an example see gLookupSetField() on our site).

The ObjectTypeCode of custom entities might be different when you deploy your customizations across different environments such as Development, Test , Acceptance or Production. You do not want to hard-code this ObjectTypeCode in your JavaScript.

The following function allows you to dynamically retrieve the ObjectTypeCode for any entity in JavaScript. In addition, this function is also capable of returning other metadata attributes for an entity e.g. Display Name. For a complete list op properties see http://msdn.microsoft.com/en-us/library/bb890357.aspx.

Security Roles
You must make sure that the appropriate security roles have read privileges on the metadata. Open each security role go to tab Customization and give read permission to the following options Entity, Attribute and Relationship, see example below:

    image

Note:
Only direct properties of the entity (EntityOnly) are returned, thus no arrays of attributes, relationships or privileges are returned !!

Code the code in the Onload event and call it using the examples below:

Read more

Display tooltips for fields in MS CRM – Part 2

October 22, 2010 by · 2 Comments 

Last week I posted an article on how to display the tooltips based on the attributes description in the metadata. Although the gSetTooltip() function works fine, there are still some things you need to be aware of.  

  1. The function does not include lookup fields
  2. It reads all the fields on the form, not just some
  3. You must ensure that each attribute has a descriptive title.
  4. Lastly, I strongly believe that the description field should contain functional information as well as technical information. The last of which you might not want to show to regular users.

Therefore I came up with a different solution that is completely dynamic and configurable by the customer. It requires a new entity in which you can enter a title per entity/attribute. Below I’ll describe each step in more detail.  

Create a new  entity  

First we need to create a new entity. Mine is called cm_tooltip. Change the name of the primary attribute to Title. And add two nvarchar fields called Entity and Attribute – see example 1.  

image
Example 1  

Read more

How to query the Metadata Service via JavaScript

October 19, 2010 by · Leave a Comment 

For one of our customers I needed to get a list of all entities and attributes in JavaScript. I found an interesting post by Customer Effective describing detailed steps on how to do this.

I made some minor changes to these functions namely that you can retrieve both the logical name as well as the display name. In addition, I added an extra check so that the function only returns customizable entities.

Security Roles
You must make sure that the appropriate security roles have read privileges on the metadata. Open each security role go to tab Customization and give read permission to the following options Entity, Attribute and Relationship, see example below:
image
Read more

Display tooltips for fields in MS CRM – Part 1

October 14, 2010 by · 6 Comments 

There is simple way to set tooltip text for field on CRM form. You can do it with following script placed on OnLoad event handler of some CRM form:

crmForm.all.<field name>_c.title = 'Tooltip text';
crmForm.all.<field name>_d.title = 'Tooltip text';

It will be hard work to create detailed tooltips for all fields placed on form using this script. Andriy Butenko has developed a script which will set the fields tooltip based on description of the attribute in the metadata.

image

image

To make this possible copy following script to OnLoad event of the form:
Read more