Thursday, June 14, 2012

Retrieving entity information programmatically

There are times that we need to retrieve information related to an entity separately. For an instance if we want to know the primary key field name in an entity or primary field id (this can be taken using the entityname + “id”) of an entity this is useful. The code snippet needed for this given below.
RetrieveEntityRequest retrieveEntityRequest = new RetrieveEntityRequest
            {
                EntityFilters = EntityFilters.Attributes,
                LogicalName = “contact”
            };

RetrieveEntityResponse retrieveEntityResponse = (RetrieveEntityResponse)Execute(retrieveEntityRequest);

if (retrieveEntityResponse != null)
            {
                return retrieveEntityResponse.EntityMetadata.PrimaryNameAttribute;
            }

The above will return the primary field name of the entity.

No comments:

Post a Comment

Retrieving Calendar of a Bookable Resource in Dynamics

There are occasions where we need to retrieve working days and working times of a resource in Dynamics grammatically. This is quite possible...