Question

I am trying to retrieve the attribute name and type that exist in an entity, Dynamic Entity to be precise. I have the following code.

DynamicEntity contactEntity = new DynamicEntity();
contactEntity.Name = EntityName.contact.ToString();

Property t = null;
foreach (Property prop_Test in contactEntity.Properties)
{
    Response.Write("<br/>Name : " + prop_Test.Name.ToString());   
}

I am getting the properties count as 0.

Is it mandatory for me to pass an id to the contact entity. Because i am trying to map attributes from the entity to the attributes i get from an excel file. The end user themselves would be doing the mapping so all i need are the attribute name and type and nothing else. For instance in SQL we have the query

SELECT * FROM TABLE_NAME WHERE 1 <> 1

This query basically returns an empty resultset with only the fieldnames. That is what i am looking for here. Is it even possible ?

Was it helpful?

Solution

In your example above, the dynamic entity does not have any properties set on it. The dynamic entity is a special type in MS CRM that is used when you do not know the CRM type until runtime. If you add properties to the dynamic entity and run your example, you will get however many properties returned that you define.

In order to get the contact attributes, you will need to reference the CRM Metadata Service as explained in the SDK.

There is an example within this download in the HowTo section that shows how to get out the entity and attribute metadata.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top