Showing posts with label Microsoft Dynamics CRM. Show all posts
Showing posts with label Microsoft Dynamics CRM. Show all posts

Friday, July 1, 2011

How to get the Entity Type Code / Object Type Code in CRM 2011 - Part 2

This is a followup to my previous post about How to get the Entity Type Code in CRM 2011. While that method works, it requires you to go to a page and manually get the type code for the entity. What we really need is a way through script to get the entity type code / object type code by passing an entity name. Well, the code below uses Microsoft's own logic and will return the entity type code / object type code for the entity name you provide it.  Let me know if you have any trouble or have any suggestions on how to improve this.

var getObjectTypeCode = function(entityName) {
/// <summary>
/// Gets the EntityTypeCode / ObjectTypeCode of a entity
/// </summary>
/// <param name="entityName" type="string">
/// Name of entity to return object type code of
/// </param>
/// <returns type="int" /> 
 var lookupService = new RemoteCommand("LookupService", "RetrieveTypeCode");
 lookupService.SetParameter("entityName", entityName);
 var result = lookupService.Execute();

 if (result.Success && typeof result.ReturnValue == "number") {
  return result.ReturnValue;
 } else {
  return null;
 }
}

Monday, June 13, 2011

How to get the Entity Type Code in CRM 2011

In CRM 4.0 you can get the ObjectTypeCode by using crmForm.ObjectTypeCode. Unfortunately, in CRM 2011 there is no explicit method in the Xrm namespace that returns the EntityTypeCode/ObjectTypeCode.  However, you can easily get the EntityTypeCode by using the Xrm.Page.context.getQueryStringParameters() method. This method will return an object with properties for each parameter in the query string. So to get the EntityTypeCode you would write something like
//var etc = Entity Type Code of active record
var etc = Xrm.Page.context.getQueryStringParameters().etc

Wednesday, April 27, 2011

Holly Cow Batman it's a Wiki

Do you have great information about MSCRM that you want to share with the world?  Then you should go to the CRM Wiki, which was just released by CRM MVPs, and add a page.  You can find the Wiki at

https://community.dynamics.com/product/crm/crmtechnical/b/crmteamblog/archive/2011/04/04/crm-mvps-introduce-the-microsoft-dynamics-crm-wiki.aspx?sms_ss=typepad&at_xt=4db7045bbb11d576%2C0