Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamics CRM how to get list of all entities

Tags:

c#

crm

Working with CRM 2013, how can I get a list of all entities in the CRM via the connectionManager class? I want to get all the entities for the current connection.

like image 638
SarrahSG Avatar asked Apr 15 '15 16:04

SarrahSG


People also ask

How do I see all entities in Dynamics 365?

You can use the Entity Metadata Browser to view entities and their properties in Dynamics 365 Customer Engagement (on-premises).


2 Answers

Thank you for your comment and answer it work now, this is my function

public static EntityMetadata[] GetEntities ( IOrganizationService organizationService)
{
    Dictionary<string, string> attributesData = new Dictionary<string, string>();
    RetrieveAllEntitiesRequest metaDataRequest = new RetrieveAllEntitiesRequest();
    RetrieveAllEntitiesResponse metaDataResponse = new RetrieveAllEntitiesResponse();
    metaDataRequest.EntityFilters = EntityFilters.Entity;

    // Execute the request.

    metaDataResponse = (RetrieveAllEntitiesResponse)organizationService.Execute(metaDataRequest);

    var entities = metaDataResponse.EntityMetadata;

    return entities;
}

and i call my function in the windows app form like this:

var allEntities = CRMHelpers.GetEntities(service);
foreach (EntityMetadata Entity in allEntities)
{
    cbxEntity.Items.Add(Entity.LogicalName);
}
like image 184
SarrahSG Avatar answered Sep 20 '22 01:09

SarrahSG


If you are looking for getting the entity metadata using code (C#) then we have inbuilt messages to get all entities and if required attribute level information as well. You can use the message "RetrieveAllEntitiesRequest". A sample code would be as follows to achieve the same.

RetrieveAllEntitiesRequest retrieveAllEntityRequest = new RetrieveAllEntitiesRequest
{
    RetrieveAsIfPublished = true,
    EntityFilters = EntityFilters.Attributes
};
RetrieveAllEntitiesResponse retrieveAllEntityResponse = (RetrieveAllEntitiesResponse)serviceProxy.Execute(retrieveAllEntityRequest);

If you need to get a specific entity information then you may use the message "RetrieveEntityRequest". A sample for the same would be as follows,

RetrieveEntityRequest entityRequest = new RetrieveEntityRequest
{
    EntityFilters = EntityFilters.Attributes,
    LogicalName = entityName,
    RetrieveAsIfPublished = true
};
RetrieveEntityResponse entityResponse = (RetrieveEntityResponse)serviceProxy.Execute(entityRequest);

Hope this is what you were looking for. Let us know if you need any more information on the same.

like image 33
Renjith Avatar answered Sep 22 '22 01:09

Renjith