Subscribe to What I've learned working with Dynamics CRM 2011        RSS Feed
-----

Introduction, and Creating Links to CRM Entities

Icon 1 Comments
Introduction

Hello everyone! I've been working with Microsoft Dynamics CRM 2011 for about two years now. There's plenty of good information out there for this product, but it's neither easy to find nor complete. The MSDN is hit or miss; many pages have no examples or more than a single sentence explanation. Then there are the dozens of blogs that seem to just steal each other's articles; nothing more frustrating than the top three hits on google have identical text (that may or may not be helpful).

With all that in mind, I decided to make a blog where I can share my experiences and insights that I've gleaned from working as a full time XRM developer.

I'll try to tag each post with the type of development it is relevant to, such as Javascript, plugins, workflows, etc...

So, welcome to the blog, and I hope that I've been able to provide some help. Feel free to request topics for new posts; I'll be glad to provide any insight I can on any topic that I can help with.

Creating Links to CRM Entities

For my first article I chose an easy one; Microsoft even has a page on the MSDN explaining it. There's a lot of information there. However, for most use cases, the information can be simplified. I'll show you the two main use cases.

Linking to Existing Records

You only need three pieces of information to link to any existing entity in CRM 2011:

  • The base URL for your CRM organization (<baseUrl>)
  • The ID of the entity (<id>)
  • The entity's ETC or ETN, your choice (<etc>/<etn>)


With these three pieces, we form one of the two following URLs:

  • http(s)://<baseUrl>/main.aspx?etc=<etc>&id=<id>&pagetype=entityrecord
  • http(s)://<baseUrl>/main.aspx?etn=<etn>&id=<id>&pagetype=entityrecord


Now that we know what we need, let's explain what these tokens are and what they represent.

The base URL is simple; it's the same URL you use to browse to the CRM directly. The standard URL is http://hostname/org/main.aspx, but your installation may be configured to use http://org.hostname/main.aspx. Either way, that's your base URL. Make sure to use the same protocol you've set CRM to use (http/https).

The entity's ID is also simple; it's the GUID that identifies the record as unique. There are several places to find a record's GUID: you could look the record up in your OrgName_MSCRM database (look for a future post about using the CRM's database), or you can Retrieve the entity via the Organization Service (or the REST endpoint; either way works) and the ID will be one of the columns/attributes returned. The logical name of this attribute is EntityLogicalNameId. So for example, Contact's ID attribute is ContactId. If you had a custom entity with a logical name of new_MyCustomEntity, the ID attribute is new_MyCustomEntityId. The ID is also embedded in the URL of the links that CRM itself makes. So if you search for an account and open it; you can copy the URL and run it through a "url decoder" and grab the ID from the decoded URL. I realize this isn't all that useful to you, since if you already have a link to the entity, you have very little need to manufacture a link. Just know that it's an option. (Note: you may have to decode the URL twice. It's sometimes embedded in the extraqs parameter, which CRM uses as an "extra" query string. It's encoded separately, then included in the main URL and re-encoded. That's why you have to decode twice).

ETN stands for Entity Type Name, which is also known as the entity's logical name. Remember, not all display names match logical names, though some will. Lead is an example where the names are identical. An example of an entity with a different logical name would be Notes. Note's logical name is "annotation".

ETC stands for Entity Type Code, which is a unique integer that identifies a particular type of entity. Every entity has a logical name and a type code. Type codes are harder to find. You can query your organizations's DB (OrgName_MSCRM) to find it; you would select ObjectTypeCode from EntityView where LogicalName = @logicalname (replace parameter with name of entity). You can also look at the table I've included at the end of this tutorial. There are also ways to retrieve the ETC of an entity with Javascript, both for an entity that you're already on the form for, and for other entities as well (though I'm not sure this way is supported or not). Look for a future post with some Javascript tips that will explain these methods.

We have all the pieces we need now, and we understand where they come from. Knowing that, we can put together a full URL. Here's an example:

http://dynamics.com/crm/main.aspx?etc=1&id=46ecb6d7-df44-4164-8680-46b616ea950e&pagetype=entityrecord
http://dynamics.com/crm/main.aspx?etc=account&id=46ecb6d7-df44-4164-8680-46b616ea950e&pagetype=entityrecord


Of course, those links doesn't go anywhere, but if that were a real CRM 2011 installation and organization, they would each link to one particular account with an id of {46ecb6d7-df44-4164-8680-46b616ea950e}.

Linking to a Create Form

Instead of linking to an existing entity, you may want to link directly to a form that will allow a user to create a new record. This is quite simple as it uses the same information as we did in the last section. The only thing you need to omit is the ID (since the record hasn't been created yet, the record does not have an ID).

Here are the two URL templates you can use:

  • http(s)://<baseUrl>/main.aspx?etc=<etc>&pagetype=entityrecord
  • http(s)://<baseUrl>/main.aspx?etn=<etn>&pagetype=entityrecord


Which would result in these sample URLs:

http://dynamics.com/crm/main.aspx?etc=1&pagetype=entityrecord
http://dynamics.com/crm/main.aspx?etc=account&pagetype=entityrecord


These would take you to a "create new account" page.

Built-in ETNs and ETCs

Normally I wouldn't just copy content. This content however is easy enough to obtain via the SDK, and I want to make sure that even if Microsoft moves the link that the data is still available. So you can either follow the link or expand the spoiler tag.

Source: http://msdn.microsof...y/bb887791.aspx

Spoiler

1 Comments On This Entry

Page 1 of 1

belgarion262 Icon

29 August 2013 - 07:00 AM
I sense this blog is going to be incredibly useful to me, having just started an Apprenticeship at Goldcrest Solutions, who literally just do Microsoft CRM!

Will be following with great interest :)
0
Page 1 of 1

Trackbacks for this entry [ Trackback URL ]

There are no Trackbacks for this entry

September 2014

S M T W T F S
 123456
78910111213
14151617 18 1920
21222324252627
282930    

Tags

    Recent Entries

    Search My Blog

    0 user(s) viewing

    0 Guests
    0 member(s)
    0 anonymous member(s)

    Categories