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.
Asked
Active
Viewed 2.1k times
9
-
If you only need to have listed the entities present on the CRM, you can install the managed solution of the SDK. it should be in your SDK folder Tools\MetadataBrowser\ as a zip file. https://msdn.microsoft.com/en-us/library/hh547411.aspx Also, yo can use the DumpEntityInfo App in SampleCode\CS\Metadata\Entities (C#) that creates an xml file with all the entities currently in the system. – Analyst Apr 15 '15 at 17:05
2 Answers
12
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);
}
-
1Why are you instantiating a new response object just to throw it away a few lines later? -- and what is the Dictionary object for? -- It doesn't look like it gets used anywhere. – BrainSlugs83 Dec 13 '16 at 22:16
7
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.
-
Thank your for your answer but when i call my function GetEntities VS has stopped working, this is my function : – SarrahSG Apr 16 '15 at 08:19
-
public static EntityMetadata[] GetEntities ( IOrganizationService service) {RetrieveAllEntitiesRequest Request = new RetrieveAllEntitiesRequest(); RetrieveAllEntitiesResponse Response = new RetrieveAllEntitiesResponse(); Request.EntityFilters = EntityFilters.All; Response = (RetrieveAllEntitiesResponse)service.Execute(Request); var entities =Response.EntityMetadata; return entities; } and i call my function in the Load form like that var allEntities = CRMHelpers.GetEntities(service); foreach (EntityMetadata Entity in allEntities) {cbxEntity.Items.Add(Entity.LogicalName);} – SarrahSG Apr 16 '15 at 08:46
-
Is it stop working (like threw some exception?) or took some time. What I have noticed is getting the metadata normally takes some more time compared to normal fetching of data. – Renjith Apr 17 '15 at 05:09