Skip to content

Get EntitySetName from Metadata

Posted in Dynamics 365, and Revive

Everybody who has worked with the Web Api, in the system formerly known as Dynamics CRM (honestly, I do not know how to call it now), must have notice that you can’t pass the EntityLogicalName to it. It expects the EntitySetName, which is a kind of plural name for the entity.
Not to be confused with the plural display name you can configure in the entity.

So far I had a little Javascript function that tried to imitade the rules wich are responsible for the generation of the EntitySetName. But since there can be some exceptions, I’m now the opinion that it would be more reliable to query the metadata directly from the system.

Here it is: Get EntitySetName from Metadata

function getEntitSetName(strEntityLogicalName)
{
    var req = new XMLHttpRequest();
    req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/" +
        "EntityDefinitions(LogicalName='" + strEntityLogicalName + "')?$select=EntitySetName", false);
    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.onreadystatechange = function ()
    {
        if (this.readyState === 4)
        {
            req.onreadystatechange = null;
            if (this.status === 200)
            {
                var result = JSON.parse(this.response);
                return result.EntitySetName;
            }
            else
            {
                return null;
            }
        }
    };
    req.send();
}

6 Comments

  1. […] and activities in Javascript. I had a look into the SDK and remembered my previous post “Get EntitySetName from Metadata“. A little modification and I get true or false from the ‘isActivity’ information […]

    25.04.2017
    |Reply

Leave a Reply

Your email address will not be published.