Skip to content

Get isActivity from Metadata

Posted in Dynamics 365, Power Platform, and Revive

This week I had to differentiate between normal entities 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 in the metadata.

Here it is fo you: Get isActivity from Metadata

function isActivity(strEntityLogicalName)
{
    var req = new XMLHttpRequest();
    req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.0/" +
        "EntityDefinitions(LogicalName='" + strEntityLogicalName + "')?$select=IsActivity", 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);
                var isActivity = result.IsActivity;
            }
        }
    };
    req.send();
}

isActivity

Be First to Comment

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    This site uses Akismet to reduce spam. Learn how your comment data is processed.