gpt4 book ai didi

javascript - 在 CRM 2011 Javascript 中获取架构名称

转载 作者:行者123 更新时间:2023-11-30 08:59:21 25 4
gpt4 key购买 nike

如何在 CRM 2011 Javascript 中获取记录中特定字段的架构名称...?

最佳答案

字段名称应与“id”属性相同。

如果您碰巧在字段的事件中工作,您总是可以在定义函数时传递执行上下文,然后在您的事件代码中使用:

executionContext.getEventSource().getName();

http://msdn.microsoft.com/en-us/library/gg334332.aspx

如果您需要基于字段 ID/名称(小写)的架构名称(大小写混合),您可以使用类似这样的东西(基于 http://crmxpg.nl/wp/2010/10/19/how-to-query-the-metadata-service-via-javascript)

function GetSchemaName() {

alert(gGetAttributeList(Xrm.Page.data.entity.getEntityName(), "thefieldname"));

}

//*********************************************************
gQueryMetadataService = function (request) {

var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
xmlhttp.open("POST", '/mscrmservices/2007/MetadataService.asmx', false);
xmlhttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xmlhttp.setRequestHeader("SOAPAction", 'http://schemas.microsoft.com/crm/2007/WebServices/Execute');
var soapMessage = "<?xml version='1.0' encoding='utf-8'?>" +
"<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' " +
"xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>" +
"<soap:Header>" +
"<CrmAuthenticationToken xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>" +
"<AuthenticationType xmlns='http://schemas.microsoft.com/crm/2007/CoreTypes'>" + AUTHENTICATION_TYPE +
"</AuthenticationType>" +
"<OrganizationName xmlns='http://schemas.microsoft.com/crm/2007/CoreTypes'>" + ORG_UNIQUE_NAME +
"</OrganizationName>" +
"<CallerId xmlns='http://schemas.microsoft.com/crm/2007/CoreTypes'>00000000-0000-0000-0000-000000000000</CallerId>" +
"</CrmAuthenticationToken>" +
"</soap:Header>" +
"<soap:Body><Execute xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>" + request +
"</Execute></soap:Body>" +
"</soap:Envelope>";
xmlhttp.send(soapMessage);
return xmlhttp.responseXML;
}

gGetAttributeList = function (entityName, fieldname) {

var request = "<Request xsi:type='RetrieveEntityRequest'>" +
"<MetadataId>00000000-0000-0000-0000-000000000000</MetadataId>" +
"<EntityItems>IncludeAttributes</EntityItems>" +
"<LogicalName>" + entityName + "</LogicalName>" +
"<IsCustomizable>1</IsCustomizable>" +
"<RetrieveAsIfPublished>true</RetrieveAsIfPublished>" +
"</Request>";

var result = gQueryMetadataService(request);
var schemaNames = result.selectNodes("//EntityMetadata/Attributes/Attribute/SchemaName");
for (var i = 0; i < schemaNames.length; i++) {
if (fieldname === schemaNames[i].text.toLowerCase()) {
return schemaNames[i].text;
}
}
return null;
}

关于javascript - 在 CRM 2011 Javascript 中获取架构名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10619733/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com