3
votes

When creating a custom Entity in Dynamics CRM 2013, you have the option of enabling Activities for that entity (i.e. in the Entity configuration screen, you can check the "Activities" checkbox).

This allows Activity records to be linked to the new custom Entity.

We have a CRM plugin developed in C# that needs to check if a custom entity is "Activity" enabled, as the plugin needs to create an Activity record linked to the custom entity record.

Is there a way to check if an Entity is "Activity" enabled programatically?

1
I did a quick check and it looks like you will have to evaluate the 1:n Relationships of your entity to find out. So yes, there is definitely a way to find out programmatically. It is merely a matter of best performance on how to retrieve this information. If you are interested I could post a basic sample for you to get started.Filburt
Hi Filburt, yes that was it, thanks for the reply.Lenny

1 Answers

7
votes

You can use the RetrieveEntityRequest to find out if an entity is enabled for activities. The RetrieveEntityResponse contains an EntityMetadata object with in it the OneToManyRelationships.

When the entity has a relationship with activitypointer entities, it is enabled for activities.

Code example:

var metaResponse = (RetrieveEntityResponse)proxy.Execute(new RetrieveEntityRequest
{
    EntityFilters = EntityFilters.Relationships,
    LogicalName = "account",
    RetrieveAsIfPublished = false
});

bool isActivityEnabled =
    metaResponse.EntityMetadata.OneToManyRelationships
    .Any(r => r.ReferencingEntity == "activitypointer");

Do not set RetrieveAsIsPublished = true. Of course setting this property can as well be omitted, but I left it in sake of clarity. Credits go to SimonM, see comments section below.