Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Answered

get all entity metadata display names via javascript?

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

  • Danilo Costa Profile Picture
    Danilo Costa 20 on at
    RE: get all entity metadata display names via javascript?

    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.

  • Danilo Costa Profile Picture
    Danilo Costa 20 on at
    RE: get all entity metadata display names via javascript?

    perfect solution worked great, thanks.

  • Verified answer
    cloflyMao Profile Picture
    cloflyMao 25,198 on at
    RE: get all entity metadata display names via javascript?

    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

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans