如果是要取得Lookup的objecttypecode:
CRM4.0:
crmForm.all.{field id}.DataValue[0].type
CRM2011:
Xrm.Page.getAttribute(“{field id}”).getValue()[0].type
如果是要取得Form的objecttypecode:
CRM4.0:
crmForm.ObjectTypeCode
CRM2011:
Xrm.Page.context.getQueryStringParameters().etc //这是一种曲折的方法,通过querystring的参数来拿。
*CRM2011也可以用4.0的方法。只是微软声称不再支持。所以尽量还是用2011的方法吧。
-------------
更新:
根据实体名称获取其Oject Type Code:
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; } }
C#:
RetrieveEntityRequest request = new RetrieveEntityRequest(); request.LogicalName = "account"; // Retrieve the MetaData. RetrieveEntityResponse response = (RetrieveEntityResponse)_service.Default.Execute(request); int objecttypecode = response.EntityMetadata.ObjectTypeCode.Value;