locked
Getting attribute logical names RRS feed

  • Question

  • How can I get the logical names of attributes in an entity to use in retrieving those columns of data?

    For example I have code which is something like.

    string[] incidentfields = new string[] { "new_testmodule_status", "incidentid", "ticketnumber", "title", "new_testmodule_contact2" };
    var entity2 = service.Retrieve(Incident.EntityLogicalName, entity.Id, new Microsoft.Xrm.Sdk.Query.ColumnSet(incidentfields));
    

    Which is OK as far a it goes but relies on me hard coding the column names in the code as strings. So lots of opportunity for error there. As far as I can see there is an attribute logicalName property that I should be able to use to identify the column names but that seems to exist only after I have retreived the columns. Surely I should be able to do something like;

    Incident incident = new Incident();
    string[] incidentfields = new string[] { "new_testmodule_status", "incidentid", "ticketnumber", "title", incident.new_testmodule_contact2.LogicalName };
    var entity2 = service.Retrieve(Incident.EntityLogicalName, entity.Id, new Microsoft.Xrm.Sdk.Query.ColumnSet(incidentfields));
    
    Obviously I've only changed the last field there for sake of example but the point is that it exists inside CRM, CRM already knows the attribute names, it's error prone using hardcoded strings. So how do I avoid that?


    Thursday, August 22, 2013 4:20 PM

All replies