locked
What happened to the Owner, Customer & Lookup classes in 2011? RRS feed

  • Question

  • If I wanted to get the name of a record Owner, I could simply grab it like this in 4.0:

    string ownerid = myDE1.Properties.Contains("ownerid") ? ((Owner)myDE1.Properties["ownerid"]).name : string.Empty;
    

    I adjusted the code to work in 2011, but the Owner class doesn’t exist in the Microsoft.Xrm.Sdk namespace:

    string ownerid = myDE1.Attributes.Contains("ownerid") ? ((Owner)myDE1.Attributes["ownerid"]).name : string.Empty;
    
    

                      
    Do I assume that the QueryExpression in 2011 will only return the GUID of the owner, then I have to execute another QueryExpression to find the name?
    Thanks for reading.

    Friday, October 14, 2011 1:22 PM

Answers

  • Assuming myDE1 is of type Entity then you'd need this:

    string ownerName = myDE1.Attributes.Contains("ownerid") ? ((EntityReference)myDE1["ownerid"]).Name : string.Empty;
    


    Gonzalo | gonzaloruizcrm.blogspot.com

    Friday, October 14, 2011 2:12 PM
    Moderator

All replies

  • All those classes have been replaced by EntityReference.

    You can still perform the same operations on EntityReference. For the owner field it can be a user/team and for customer it can be account/contact.


    Gonzalo | gonzaloruizcrm.blogspot.com

    Friday, October 14, 2011 1:36 PM
    Moderator
  • not sure I follow...  Is this what you had in mind?

                       string ownerid = myDE1.Attributes.Contains("ownerid") ? new EntityReference(SystemUser.EntityLogicalName, (Guid)myDE1.Attributes["ownerid"]).Name : string.Empty;
    
    

     

    Friday, October 14, 2011 2:05 PM
  • Assuming myDE1 is of type Entity then you'd need this:

    string ownerName = myDE1.Attributes.Contains("ownerid") ? ((EntityReference)myDE1["ownerid"]).Name : string.Empty;
    


    Gonzalo | gonzaloruizcrm.blogspot.com

    Friday, October 14, 2011 2:12 PM
    Moderator
  • Cool, thank you.  I'm assuming the Lookup gets changed like this:

                        Guid regardingobjectid = myDE1.Attributes.Contains("regardingobjectid") ? ((EntityReference)myDE1.Attributes["regardingobjectid"]).Id : Guid.Empty;
    
    

     

    Friday, October 14, 2011 2:27 PM
  • Yes that gives you the ID of the regarding object.

    Gonzalo | gonzaloruizcrm.blogspot.com

    Friday, October 14, 2011 2:30 PM
    Moderator
  • How about the type?  I'm looking for the entity type for a Regarding field.

                                Guid regardingobjectidGUID = myDE5.Attributes.Contains("regardingobjectid") ? ((EntityReference)myDE5.Attributes["regardingobjectid"]).Id : Guid.Empty;                            string regardingobjectidname = myDE5.Attributes.Contains("regardingobjectid") ? ((EntityReference)myDE5.Attributes["regardingobjectid"]).Name : string.Empty;                            string regardingobjectidtype = myDE5.Attributes.Contains("regardingobjectid") ? ((EntityReference)myDE5.Attributes["regardingobjectid"]).type : string.Empty;
    

     

    Friday, October 14, 2011 6:45 PM
  • For the type:

    string regardingobjecttype = myDE1.Attributes.Contains("regardingobjectid") ? ((EntityReference)myDE1.Attributes["regardingobjectid"]).LogicalName : string.Empty


    Gonzalo | gonzaloruizcrm.blogspot.com

    Friday, October 14, 2011 7:36 PM
    Moderator