Upgrade Your URL Parameter References

There are times when working in either JavaScript or .NET where you need to either display a CRM record or give the user the option of clicking a link to display a CRM record.

The CRM 2011 SDK documents this process here:

Open Forms, Views, Dialogs and Reports with a URL?

It also includes a very important note:

Do not use the etc (entity type code) parameter that contains an integer code for the entity. This integer code varies for custom entities in different organizations.

One of the required parameters on a Dynamics CRM URL is the type of entity you’re opening. This is specified by one of these parameters:

  • etc – for Entity Type Code
  • etn – for Entity Type Name

 

In Dynamics CRM 4.0, (and 3.0 for that matter), most people used the etc parameter.  This cause some very bad side-effects when moving your code from installation to installation (development, test, production).  The Entity Type Code could, and often did, vary from installation to installation.

etn, the second parameter, allows you to specify the name of the entity: account, contact, new_entity, etc.  This information does not change from installation to installation.

Anecdotal Evidence:

I once saved 30 minutes per roll-out by switching all of my URL references from etc to etn. Before that, I had to hand-modify my code to reference the proper Entity Type Code and had to maintain an Excel worksheet with that information.

etn has been around since at least CRM 4.0 but you can save yourself a lot of trouble in the future, by converting your code from etc to etn.

 

Problems and Issues

I ran into an unexpected situation during an upgrade that quite honestly, left me a bit baffled. It seems a breaking change was introduced during the CRM 2011 upgrade process.

 

Some Background

In CRM 4.0, you could open an Entity record with either one of the following URLs:

http://crm2011/Contoso/userdefined/edit.aspx?id=%7bE50B1A7B-1AA2-E211-953E-00155D200507%7d&etn=new_entity

http://crm2011/Contoso/userdefined/edit.aspx?id=%7bE50B1A7B-1AA2-E211-953E-00155D200507%7d&etc=10010

The difference being using the parameter etn (entity type name) instead of etc (entity type code). Using etn is preferable because it causes fewer issues when migrating from one system to another (development, test, production).

This technique is used extensively in an xRM scenario where you may have additional web pages that use or reference CRM data. It is common to have a screen artifact, like a button, that will open a CRM record when pressed and the URLs listed above are what is used.

.

The Issue

It would seem that the etn parameter is no longer supported by the edit.aspx page in CRM 2011 for what appears to be custom entities only. It seems to work fine for out-of-the-box entities.

The Solution

The use of etn is ONLY supported on main.aspx, AND you need to specify the &pagetype=entityrecord parameter, like this:

http://crm2011/Contoso/main.aspx?etn=new_entity&id=%7bBB81247D-7494-E111-913F-00155D00650B%7d&pagetype=entityrecord

 

Further Confusion

I am sure you have noticed, and maybe used, the Copy a Link/Email a Link functionality built into CRM:

image_thumb

This is a very handy feature and I use it all of the time.

Unfortunately, it will return a different URL depending on the entity being used. Standard entities will produce a URL with main.aspx while custom entities will produce edit.aspx.

And again, only main.aspx can use the etn parameter.

 

Additional Reading

I cover this topic a little more in this article:

Upgrade Your URL Parameter References

and I’ll update that article to reflect this new information.

Leave a Reply 2 comments