Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Metadata call in D365 using WebAPI in JavaScript

Posted on by Microsoft Employee

I'm using Webapi (Xrm.WebApi.online.execute(request).then(successCallback, errorCallback)) to get all the entities within a system, but it throws error as 

Expression of type 'Edm.String' cannot be converted to type 'Microsoft.Dynamics.CRM.EntityFilters

Code is : 

var request = {
RetrieveAsIfPublished :true,
EntityFilters: "Entity",
getMetadata: function () {
var metadata = {
boundParameter: null,
operationType: 1,
operationName: "RetrieveAllEntities",
parameterTypes: {
"RetrieveAsIfPublished": {
"typeName": "Edm.Boolean",
"structuralProperty": 0
},
"EntityFilters": {
"typeName": "Microsoft.Dynamics.CRM.EntityFilters",
"structuralProperty": 0
}
}
}
return metadata;
}
}
Xrm.WebApi.online.execute(request).then(successCallback, errorCallback);

Any Ideas how to convert string to enum or the approach I'm using is incorrect?

*This post is locked for comments

  • PascalH Profile Picture
    PascalH 5 on at
    RE: Metadata call in D365 using WebAPI in JavaScript

    Hi, did you find a Solution for this? i tried this for Version 9.2 but i don't get it working.

    Thank you

    Pascal

  • Suggested answer
    keyur7379 Profile Picture
    keyur7379 900 on at
    RE: Metadata call in D365 using WebAPI in JavaScript

    It will help you to get all entity and it attributes.

    function startSample() {

                //alert("Keyur");
                ///<summary>
                /// Initializes the sample when the document is ready
                ///</summary>
                //Assign the global variables
                results = document.getElementById("results");
                message = document.getElementById("message");
                <!-- alertFlag = document.getElementById("dispalert"); -->
                //document.getElementById("btnstartSample").setAttribute("disabled", "disabled");
                //Retrieve entities
                SDK.Metadata.RetrieveAllEntities(SDK.Metadata.EntityFilters.Entity,
                    false,
                    successRetrieveAllEntities,
                    errorRetrieveAllEntities);
                //setText(message, "Loading...");

            }

            function successRetrieveAllEntities(entityMetadataCollection) {
                ///<summary>
                /// Receives the data from SDK.Metadata.RetrieveAllEntities and
                /// appends a list item to results for each one.
                ///</summary>

                entityMetadataCollection.sort(function(a, b) {
                    if (a.LogicalName < b.LogicalName) {
                        return -1
                    }
                    if (a.LogicalName > b.LogicalName) {
                        return 1
                    }
                    return 0;
                });

                for (var i = 0; i < entityMetadataCollection.length; i++) {

                    var entity = entityMetadataCollection[i];
                    var entityNode = document.createElement("li");
                    var entitySpan = document.createElement("span");
                    //debugger;
                    if (entity.DisplayName != null && entity.DisplayName.UserLocalizedLabel != null) {
                        setText(entitySpan, entity.DisplayName.UserLocalizedLabel.Label);
                        entitySpan.title = entity.DisplayName.UserLocalizedLabel.Label;
                    }
                    //setText(entitySpan, entity.SchemaName);
                    entitySpan.id = entity.LogicalName;
                    
                    entitySpan.attributesRetrieved = false;
                    // Add the event handler to retrieve attributes
                    entitySpan.onclick = retrieveAttributes;
                    //entitySpan.style.cursor = "pointer";
                    entitySpan.style="font-size:12.5px; font-family:Segoe UI, Tahoma, sans-serif; font-style:normal; color:dimgray; cursor:pointer;";
                    entityNode.appendChild(entitySpan);
                    results.appendChild(entityNode);

                }

                //setText(message, entityMetadataCollection.length +
                //" entities retrieved. Click each entity to retrieve the entity attributes.");
                if (alertFlag.checked == true)
                    alert("Entity List Retrieved.");
            }

  • Suggested answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: Metadata call in D365 using WebAPI in JavaScript

    Hi Vijay,

    You will have to pass "Microsoft.Dynamics.CRM.EntityFilters'Entity'" instead of "Entity" for the EntityFilter paramter.

    Refer this: community.dynamics.com/.../passing-enumtype-parameter-in-web-api-in-crm-2016

    crmorg.crm.dynamics.com/.../RetrieveAllEntities(RetrieveAsIfPublished=@RetrieveAsIfPublished,EntityFilters=@EntityFilters);@EntityFilters=Microsoft.Dynamics.CRM.EntityFilters'Entity'

    Hope this helps.

  • Suggested answer
    Arun Vinoth Profile Picture
    Arun Vinoth 11,613 on at
    RE: Metadata call in D365 using WebAPI in JavaScript

    You can use these URIs to pull the metadata you needed.

    https://<your org name>.crm.dynamics.com/api/data/v8.2/

    or

    https://<your org name>.crm.dynamics.com/api/data/v8.2/EntityDefinitions

    Read more: stackoverflow.com/.../7920473

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,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans