web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How do I get a fields schema name?

(0) ShareShare
ReportReport
Posted on by 3,755

I want to get the schema name of a Field and use it in javascript. Does anyone know how to do this:

For instance, I have a Post Code field, with schema name new_postcode.

Any assistance would be great.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    purwar purwar Profile Picture
    2,836 on at

    The name for a field should be the same as the "id" property.

    If you happen to be working from a field's event, you can always pass the execution context when defining the function and then in your event code use:

    executionContext.getEventSource().getName();

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

    If you need the schema name (mixed case) based on the field id/name (lower case) you can use something like this (based on 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", 'schemas.microsoft.com/.../Execute&);

       var soapMessage = "<?xml version='1.0' encoding='utf-8'?>" +

                         "<soap:Envelope xmlns:xsi='www.w3.org/.../XMLSchema-instance& " +

                         "xmlns:xsd='www.w3.org/.../XMLSchema& xmlns:soap='schemas.xmlsoap.org/.../& +

                         "<soap:Header>" +

                         "<CrmAuthenticationToken xmlns='schemas.microsoft.com/.../WebServices& +

                         "<AuthenticationType xmlns='schemas.microsoft.com/.../CoreTypes& + AUTHENTICATION_TYPE +

                         "</AuthenticationType>" +

                         "<OrganizationName xmlns='schemas.microsoft.com/.../CoreTypes& + ORG_UNIQUE_NAME +

                         "</OrganizationName>" +

                         "<CallerId xmlns='schemas.microsoft.com/.../CoreTypes& +

                         "</CrmAuthenticationToken>" +

                         "</soap:Header>" +

                         "<soap:Body><Execute xmlns='schemas.microsoft.com/.../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;

    }

  • Hussman Profile Picture
    3,755 on at

    Thanks for the reply. What i am trying to do is take a field and capitalise the text. For instance, the Name field (new_name), I would like to capitalise the input the user types in. rather than bind the name to the field, I would like to make the code reusable so that it can be used form-wide.

    is there a quicker way than using a SOAP request?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans