Search code examples
c#dynamics-crmdynamics-crm-2013

Why is Dynamics CRM 2015 SDK RetrieveEntityRequest is not returning IsLogical in AttributeMetadata?


Given the following simple CRM SDK code:

using (var os = new OrganizationService(CrmConnection.Parse(".... some crm connection ..... "))
{
    var reReq = new RetrieveEntityRequest();
    reReq.EntityFilters = EntityFilters.All;
    reReq.RetrieveAsIfPublished = true;
    reReq.LogicalName = "opportunity";

    var reRes = os.Execute<RetrieveEntityResponse>(reReq);

    // null in my case?
    Console.WriteLine("AccountId: IsLogical = {0}", reRes.EntityMetadata.Attributes[0].IsLogical.Value) 

}

Why does IsLogical of the AccountId attribute (infact all attributes) not include a value (e.g is always null)

enter image description here

My understanding here it should be True for AccountId as this is a logical attribute.

More info Im using the 2015 SDK Libraries from NUGET, and I am connecting to a 2013 instance of CRM. Could this be the incompatibility, Am I using the right libraries?

Many Thanks!


Solution

  • The purpose of the IsLogical attribute, as documented in the SDK, is for use in determining the sort-ability of a calculated field.

    Per the SDK (link from BlueSam's answer):

    When you use logical attributes as sources for a calculated field the values in the calculated field cannot be sorted.

    If you are targeting a 2013 instance the value will be null. 2013 did not have calculated fields so it did not have a need for the IsLogical attribute.

    If you are targeting a 2015 instance and looking at the IsLogical property for accountid the value will be true because accountid on the opportunity entity is a foreign key reference to the account entity.

    The rule for calculated field is if the calculated field uses any field where IsLogical == true then the calculated field cannot be used for sorting.

    It does NOT mean that the field is not editable on the UI, although it is true that many logical fields will not by editable on the UI it is not a rule per the SDK.

    I modified your code to show IsLogical for all fields on the entity:

    var reReq = new RetrieveEntityRequest();
    reReq.EntityFilters = EntityFilters.All;
    reReq.RetrieveAsIfPublished = true;
    reReq.LogicalName = "opportunity";
    
    var reRes = (RetrieveEntityResponse)conn.Execute(reReq);
    
    foreach (var att in reRes.EntityMetadata.Attributes.OrderBy (a => a.LogicalName))
    {
        Console.WriteLine("{0} IsLogical={1}",att.LogicalName, att.IsLogical.Value);
    }