views:

2541

answers:

4

I am back again with another question on ms crm.

The latest thing i am trying to do is 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 ?

+1  A: 

Can the metadata service help you out here?

Donnelle
+2  A: 

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.

SaaS Developer
A: 

Thanks both of you. The Metadataservice did help in resolving this issue. Thanks again :).

vikramjb
No problem. Didn't have time right then to answer more but figured it might give you a starting point!
Donnelle
A: 

Salve a tutti,

Io invece vorrei avere una lista delle label degli attributi, quindi non l'attribute name (esempio, per l'account vorrei ottenere "Relationship Type" e non "customertypecode"), senza dover aprire la form e scrivere su un excel il nome di tutte le label. Esiste un modo per farlo lato DB? Esiste una tabella sul DB CRM che mi restituisca i "friendly name" degli attributi di una data entità?

Grazie mille.

Marco

Marco