Retrieve CRM Entity Attributes List

To retrieve CRM Entity Attributes List, you will be require to retrieve metadata information through RetrieveAllEntitiesRequest.

After retrieving the metadata, you will get complete list of attributes listed for Entity that you have pass. You can use the following code given below:

            // Retrieve the MetaData.

            RetrieveEntityRequest metaDataRequest = new RetrieveEntityRequest();


            RetrieveEntityResponse metaDataResponse = new RetrieveEntityResponse();


            metaDataRequest.EntityFilters = EntityFilters.Attributes;


            metaDataRequest.LogicalName = LOGICAL NAME;

                                          // your entity logical name goes here like “account”


            metaDataResponse = (RetrieveEntityResponse)service.Execute(metaDataRequest);


            EntityMetadata currentEntity = metaDataResponse.EntityMetadata;


            //AttributeMetadata contains all the metadata for an entity attribute.


            foreach (AttributeMetadata attribute in currentEntity.Attributes)

            {


                var attributeName = attribute.LogicalName;

            }


Thanks.

Retrieve CRM business Entities

To retrieve CRM business entities, you will be require to retrieve metadata information through RetrieveAllEntitiesRequest. 

 After retrieving the metadata, you will get complete list of entities listed in CRM whether it is system, business or custom entity. You can use the following code given below:

               RetrieveAllEntitiesRequest req = new RetrieveAllEntitiesRequest();

               req.EntityFilters = EntityFilters.Entity;

               req.RetrieveAsIfPublished = true;

               RetrieveAllEntitiesResponse response=

                                     (RetrieveAllEntitiesResponse)service.Execute(req);

                foreach (EntityMetadata currentEntity in response.EntityMetadata)

                          {

                                 string oEntity = “”;

                                  // oEntity will provide you the name of Entities

                                  oEntity = currentEntity.SchemaName;                          

                           }

As you might be aware there are 325 entities(approx) in default CRM so you must not be interested in each and every Entities to list in. For this purpose there are many properties which are available in class

RetrieveAllEntitiesRequest which we can use as to filter the list, such as

               foreach (EntityMetadata currentEntity in response.EntityMetadata)

                        {

                           //property used to filter the entities list

                            if (currentEntity.IsValidForAdvancedFind.HasValue &&

                                currentEntity.IsValidForAdvancedFind.Value &&

                                currentEntity.CanBeRelatedEntityInRelationship.Value &&

                                currentEntity.CanBePrimaryEntityInRelationship.Value &&

                                currentEntity.CanTriggerWorkflow.Value &&

                                currentEntity.CanCreateViews.Value &&

                                currentEntity.CanCreateForms.Value &&

                                currentEntity.CanCreateCharts.Value &&

                                currentEntity.CanCreateAttributes.Value)

                            {

                                string oEntity = “”;

                                oEntity = currentEntity.SchemaName;

                             }

                        }

If you can see i have used some of the filters such as IsValidForAdvancedFind, CanCreateViews, CanCreateForms etc which basically filter your list to almost 40 42 list of business entities. you can use more filters if you wish to filter the list further.

Thanks

Filter Grid using JavaScript on MS CRM 2016 and above


Since there is no supported way to filter a grid over MS CRM till now. An unsupported way expire from version to version.

For CRM 2016 and above, use below code to filter a sub grid if parent entity and child entity doesn’t have any relationship and you wish to filter a grid base on lookup value.

function FilterSubgrid()

{

    var filterId = Xrm.Page.data.entity.getId();

    var yoursubgridnameObject = window.parent.document.getElementById(“<GridName>”);

    if (yoursubgridnameObject == null || yoursubgridnameObject.control == null) {

        setTimeout(‘FilterSubgrid()’, 1000);

        return;

    }

    if (filterId == null) return;

    var fetchXml = “<fetch version=’1.0′ output-format=’xml-platform’ mapping=’logical’       distinct=’true’>”;

    …

    fetchXml =fetchXml+ “</fetch>”;

    yoursubgridnameObject.control.SetParameter(“fetchXml”, fetchXml);

    yoursubgridnameObject.control.refresh();

}

Thanks.