簡體   English   中英

在CRM 2011 Javascript中獲取架構名稱

[英]Get the Schema name in CRM 2011 Javascript

如何在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-通過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;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM