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 :
Customer experience | Sales, Customer Insights,...
Answered

get all entity metadata display names via javascript?

(0) ShareShare
ReportReport
Posted on by 20

Hello, I'm creating a Js so that it brings me the Schema name, Type, of an entity on the console.
so far I can do it, what I'm having trouble with is bringing all the DisplayName and field size of all the fields of the selected entity.

Follow current code please help me with this question.
Thanks.

function TesteCa() {

    console.log("INICIO MEU LOG");

    var req = new XMLHttpRequest();
    req.open("GET", Xrm.Page.context.getClientUrl()   "/api/data/v8.2/EntityDefinitions(LogicalName='account')/Attributes?$select=SchemaName", true);
    req.setRequestHeader("OData-MaxVersion", "4.0");
    req.setRequestHeader("OData-Version", "4.0");
    req.setRequestHeader("Accept", "application/json");
    req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
    req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
    req.onreadystatechange = function () {
        if (this.readyState === 4) {
            req.onreadystatechange = null;
            if (this.status === 200) {
                debugger;

                var results = JSON.parse(this.response);

                for (var i = 0; i < results.value.length; i  ) {

                    console.log("Schema Name: "   results.value[i].SchemaName   ", Type: "   results.value[i]["@odata.type"]);

                    //document.getElementById("Schema Name: "   results.value[i].SchemaName   ", Type: "   results.value[i]["@odata.type"]).innerHTML = results;
                }
            } else {
                Xrm.Utility.alertDialog(this.statusText);
            }
        }
    };
    req.send();


}

he returns me
Schema Name: TerritoryIdName,
Type: # Microsoft.Dynamics.CRM.StringAttributeMetadata

I need to add it
DisplayName
Size

Thanks

I have the same question (0)
  • Verified answer
    cloflyMao Profile Picture
    25,210 on at

    Hi Danilo,

    Try using $expand=Attributes for your query.

    https://docs.microsoft.com/en-us/powerapps/developer/data-platform/webapi/query-metadata-web-api#querying-entitymetadata-attributes

    I have modified you code, but not sure what does the  your "Size" refer to, so I list all string type fields and their DatabaseLength property.

    (It seems that for other types of fields besides String, they don't have property which is similar to size.)

    Please let me know whether the code would work for you.

    TesteCa();
    
    function TesteCa() {
    
        console.log("INICIO MEU LOG");
    
        var req = new XMLHttpRequest();
        req.open("GET", Xrm.Page.context.getClientUrl()   "/api/data/v8.2/EntityDefinitions(LogicalName='account')?$select=LogicalName&$expand=Attributes", true);
        req.setRequestHeader("OData-MaxVersion", "4.0");
        req.setRequestHeader("OData-Version", "4.0");
        req.setRequestHeader("Accept", "application/json");
        req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
        req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
        req.onreadystatechange = function () {
            if (this.readyState === 4) {
                req.onreadystatechange = null;
                if (this.status === 200) {
    
                    var results = JSON.parse(this.response);
    
                    for (var i = 0; i < results.Attributes.length; i  ) {
    
                        if (results.Attributes[i].AttributeType === 'String') {
                            if (results.Attributes[i].DisplayName.LocalizedLabels.length > 0) {
                                console.log("Display Name: "   results.Attributes[i].DisplayName.LocalizedLabels[0].Label   ", Size: "   results.Attributes[i].DatabaseLength);
                            }
                        }
    
                    }
                    
                } else {
                    Xrm.Utility.alertDialog(this.statusText);
                }
            }
        };
        req.send();
    
    }

    pastedimage1610520964637v1.png

    Regards,

    Clofly

  • Danilo Costa Profile Picture
    20 on at

    perfect solution worked great, thanks.

  • Danilo Costa Profile Picture
    20 on at

    so that I can get all the entities

    and when to choose the entity dynamically

    lists this data for each entity

    Example

         | ENTITY NAME: account DISPLAYED NAME: Address 1: UPS zone | SCHEME NAME: Address1_UPSZone | TYPE: String | SIZE: 8 |

    o (| ENTITY NAME: account) I will define it in a drop-down list for the user to choose the entity, and so choose to list the fields with the data above.

    can I do this by taking all the values of (/api/data/v8.2/EntityDefinitions)?

    How could you pass the entity dynamically and select

    Example /api/data/v8.2/EntityDefinitions(LogicalName='account ')

    and return

    DISPLAY NAME: Address; SCHEME NAME: Address1_UPSZone; TYPE: String; SIZE: 8

    And with your help I managed to return those above.

    Now I need a solution to be a dynamic choice.

    in Javascript or Webresource

    Thank you in advance.

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 > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 177 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 110

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 61 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans