locked
Retrieve Attribute Description RRS feed

  • Question

  • I found something interesting,

    function lookForFieldByLabel(label)
    {
      var labelNodes = crmForm.getElementsByTagName("label");
      var searchNode = null;

      for (index in labelNodes)
     {
        if (labelNodes[index].innerHTML != null && labelNodes[index].innerText == label)
        {
          var searchNode = labelNodes[index];

          if (typeof(searchNode.htmlFor) != "undefined" && searchNode.className == "")
         {
            return searchNode.htmlFor;
          }
        }
      }
    }

    alert(lookForFieldByLabel("Vendor"));

    The result is show attribute name which is vendorname. How to get the popup as attribute description?

    Thanks.

    David

    Wednesday, January 6, 2010 11:09 AM

Answers

  • Hi, David.

    Check this url .
    Truth is opened the prepared mind

    My blog (english)
    Мой блог (русскоязычный)
    Thursday, January 7, 2010 5:30 PM
    Moderator
  • Hi Andriy,

    Thanks for your help. I really appreciate that because the code is short and clear. I manage to get some code from others source, this code will show all required attribute description by entity.

    function QueryMetadataService(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;
    }

    // This function gets the metadata for the attributes of an entity, then assigns them to the title tooltip
    function MetaToTitleTips(entityName) {
        var request = "<Request xsi:type='RetrieveEntityRequest'>" +
            "<MetadataId>00000000-0000-0000-0000-000000000000</MetadataId>" +
            "<EntityItems>IncludeAttributes</EntityItems>" +
            "<LogicalName>" + entityName + "</LogicalName>" +
            "<RetrieveAsIfPublished>true</RetrieveAsIfPublished>" +
            "</Request>";
        var result = QueryMetadataService(request);
     
     for (var i in crmForm.all) {
      var field = crmForm.all[i];
      // Avoid errors at all costs, try to use only actual crm fields and not other web form IDs
      if (field != null && field.id != null && field.id != "" && field.id != "undefined" && field.id.substring(0,1) != "{" && field.id.substring(0,3) != "tab" && field.id.substring(field.id.length-6) != "_ledit" && field.id != "crmTabBar" && field.id != "Notifications" && field.id.substring(0,12) != "notescontrol") {
       var logName;
       var idLen = field.id.length;
       // This gets the id name for _c and _d label elements for the field row/cell
       if (field.id.substring(idLen-2,idLen-1) == "_") {
        logName = field.id.substring(0,idLen-2);
       }
       else {
        logName = field.id;
       }
       if(document.getElementById(logName) != null) {
        var desc = result.selectSingleNode("//EntityMetadata/Attributes/Attribute[LogicalName='" + logName + "']/Description/UserLocLabel/Label");
        if(desc != null) {
         field.title = desc.text;
        }
       }
      }
     }
    }
    MetaToTitleTips(crmForm.ObjectTypeName);

    Many Thanks,

    David Ho

    Monday, January 18, 2010 9:46 AM

All replies

  • Hi, David.

    You can use MetaDataService to get such information. Sample how to use MetaDataService via JavaScript (Entity list retrieve) you can find here .
    Truth is opened the prepared mind

    My blog (english)
    Мой блог (русскоязычный)
    • Proposed as answer by D-Virdi Wednesday, January 6, 2010 12:29 PM
    Wednesday, January 6, 2010 11:15 AM
    Moderator
  • // Create an authentication token.
    CrmAuthenticationToken token = new CrmAuthenticationToken();
    token.OrganizationName = "AdventureWorksCycle";

    // You can use enums.cs from the SDK\Helpers folder to get the enumeration for Active Directory authentication.
    token.AuthenticationType = 0;

    // Create the metadata Web service.
    MetadataService metadataService = new MetadataService();
    metadataService.Url = "http://<servername>:<port>/MSCRMServices/2007/MetadataService.asmx";
    metadataService.CrmAuthenticationTokenValue = token;
    metadataService.Credentials = System.Net.CredentialCache.DefaultCredentials;
    metadataService.PreAuthenticate = true;

    // Create the request.
    RetrieveAttributeRequest attributeRequest = new RetrieveAttributeRequest();
    attributeRequest.EntityLogicalName = EntityName.contact.ToString();
    attributeRequest.LogicalName = "vendorname";
    // Retrieve only the currently published changes, ignoring the changes that have
    // not been published.
    attributeRequest.RetrieveAsIfPublished = false;

    RetrieveAttributeResponse attributeResponse = (RetrieveAttributeResponse)metadataService.Execute(attributeRequest);

    the you can access the all the proprties of atttibuteresponse where you will find description.


    Dare to promise
    • Proposed as answer by D-Virdi Wednesday, January 6, 2010 12:37 PM
    Wednesday, January 6, 2010 12:37 PM
  • Hi Andriy,

    Thanks for your rapid respond. After i go thru your java script, still don't know where to define the attribute description under Java Script and popup the message. Could you just highlight that portion of defining attribute description. Prefer in Java Script. Thanks.

    Regards,

    David
    Thursday, January 7, 2010 8:01 AM
  • Hi Virdi,

    Thanks a lot. Since i'm not familiar with Plug-in (.Net), so really dont understand what is inside. However, i still appreciate you help. Prefer in Java Script. Thanks.


    Regards,

    David Ho

    Thursday, January 7, 2010 8:05 AM
  • Hi, David.

    Check this url .
    Truth is opened the prepared mind

    My blog (english)
    Мой блог (русскоязычный)
    Thursday, January 7, 2010 5:30 PM
    Moderator
  • Hi Andriy,

    Thanks for your help. I really appreciate that because the code is short and clear. I manage to get some code from others source, this code will show all required attribute description by entity.

    function QueryMetadataService(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;
    }

    // This function gets the metadata for the attributes of an entity, then assigns them to the title tooltip
    function MetaToTitleTips(entityName) {
        var request = "<Request xsi:type='RetrieveEntityRequest'>" +
            "<MetadataId>00000000-0000-0000-0000-000000000000</MetadataId>" +
            "<EntityItems>IncludeAttributes</EntityItems>" +
            "<LogicalName>" + entityName + "</LogicalName>" +
            "<RetrieveAsIfPublished>true</RetrieveAsIfPublished>" +
            "</Request>";
        var result = QueryMetadataService(request);
     
     for (var i in crmForm.all) {
      var field = crmForm.all[i];
      // Avoid errors at all costs, try to use only actual crm fields and not other web form IDs
      if (field != null && field.id != null && field.id != "" && field.id != "undefined" && field.id.substring(0,1) != "{" && field.id.substring(0,3) != "tab" && field.id.substring(field.id.length-6) != "_ledit" && field.id != "crmTabBar" && field.id != "Notifications" && field.id.substring(0,12) != "notescontrol") {
       var logName;
       var idLen = field.id.length;
       // This gets the id name for _c and _d label elements for the field row/cell
       if (field.id.substring(idLen-2,idLen-1) == "_") {
        logName = field.id.substring(0,idLen-2);
       }
       else {
        logName = field.id;
       }
       if(document.getElementById(logName) != null) {
        var desc = result.selectSingleNode("//EntityMetadata/Attributes/Attribute[LogicalName='" + logName + "']/Description/UserLocLabel/Label");
        if(desc != null) {
         field.title = desc.text;
        }
       }
      }
     }
    }
    MetaToTitleTips(crmForm.ObjectTypeName);

    Many Thanks,

    David Ho

    Monday, January 18, 2010 9:46 AM