CRM2011 How to get object type code by object name in Javascript?

I have a search box in the form, before I select the related object to search, I check some conditions, if not pass, I overwrite the onclick event to notify the user; else, I need to rewrite the onclick event to show the search box so that the user can select the entity.

So, I need an object type code for this search, but before choosing, there is no value, then I can’t get an object type code using this code: var objecttypecode = Xrm.Page.getAttribute ("field id") .getValue ( ) [0] .type;

How to get an object type code by object name?

+4
source share
2 answers

I will learn how to do this:

function GetObjectTypeCode(entityName) { try { 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; } } catch (ex) { throw ex; } } 
+5
source

One of the supported methods is using the metadata service, and then retrieving the object type code, etc. (entity type code).

0
source

Source: https://habr.com/ru/post/1397560/


All Articles