none
FetchXml Link-Entity Display Link Attribute

    Question

  •                     Query = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
        "<entity name='contact'> " +
        "<attribute name='fullname' /> " +
        "<attribute name='firstname' /> " +
        "<attribute name='contactid' />" +
        "<order attribute='fullname' descending='true' />" +
        "<link-entity name='account' from='accountid' to='msa_managingpartnerid' visible='false' link-type='outer' alias='a_a5eac3556ee4e011bfce782bcb1b2b74'>" +
          "<attribute name='address1_city' />" +
        "</link-entity>" +
        "</entity>" +
        "</fetch>"

    My query is runing fine C# CRM 2011.

    I want to display address1_city attribute on page (Link-entity Attribute).

    But i dont know how to retrieve this.

    All above attributes are displayed using this line of code.

    entity.GetAttributeValue<string>("firstname")

    but not Link entity Attribute

    Please told me how to get Address1

    Thanks


    Thursday, October 27, 2011 12:40 PM

Answers

All replies

  • Thanks for Reply Jamie Miley

    I am using your code as you have told in your blog.

    but i m passing my fetchxml as shown above but please told how to get related entity record from RetriveMultipleResponse how to display them.

    Thanks

                //FetchXmlToQueryExpressionRequest req = new FetchXmlToQueryExpressionRequest();
                string fetchquery = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
      "<entity name='contact'> " +
        "<attribute name='fullname' /> " +
        "<attribute name='contactid' />" +
        "<order attribute='fullname' descending='true' />" +
        "<link-entity name='account' from='accountid' to='msa_managingpartnerid' visible='false' link-type='outer' alias='a_a5eac3556ee4e011bfce782bcb1b2b74'>" +
          "<attribute name='territorycode' />" + // i want this value to be shown
        "</link-entity>" +
      "</entity>" +
    "</fetch>";
    Thursday, October 27, 2011 3:22 PM
  • Does that call work as written?  If so, you should try to run it the C# code through the soaplogger solution in the SDK to examine the response.  If you can see the value there, you can get to it in code.

    However, I was not aware you could include link entity attributes in your result sets.  

    I usually do this by using a retrieve call to reach across a specified relationship to get the main entities and related entities all in one call.  Look at what I am doing in the second example in this blog post.

    http://mileyja.blogspot.com/2011/04/how-to-use-retrieve-messages-in-jscript.html

    Also, if you are doing jscript, this post should help you learn how to parse the returned xml envelope using DOM.

    http://mileyja.blogspot.com/2011/03/microsoft-dynamics-crm-2011-parsing.html


    Jamie Miley
    Check out my about.me profile!
    http://mileyja.blogspot.com
    Linked-In Profile
    Follow Me on Twitter!
    Thursday, October 27, 2011 3:39 PM
  • Sorry to jump in... i think i have seen before that when you use link entity... u define an alias. I can see you have done that. Now when you need to access the property of linked enity it should be referred as alias.attribute name.

    Can you check that?

    Sam


    Web: http://www.inogic.com
    Blog: http://inogic.blogspot.com
    Email: news@inogic.com
    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    • Proposed as answer by Sam - InogicMVP Thursday, October 27, 2011 4:09 PM
    • Unproposed as answer by MubasherSharif Friday, October 28, 2011 11:37 AM
    Thursday, October 27, 2011 4:09 PM
  • Hi, I agree with Sam: the index to retrieve this attribute will be:

    entity.GetAttributeValue<string>("a_a5eac3556ee4e011bfce782bcb1b2b74.address1_city");

     


    Infusion | xrm2011.wordpress.com | @fantocci
    Thursday, October 27, 2011 4:31 PM
  • I am pretty sure I have seen forum threads where people try this and it hasn't worked.  Please let us know if you get this to work or not.  Otherwise the retrieve method I proposed that uses the relationship name will also work.
    Jamie Miley
    Check out my about.me profile!
    http://mileyja.blogspot.com
    Linked-In Profile
    Follow Me on Twitter!
    Thursday, October 27, 2011 5:47 PM
  • I just ran the RetrieveMultipleConditionOperatorsFetch from the sample code in the SDK and added account name as an attribute in the linked-entity.  You can then access it as follows:

     

    entityResults.Entities[0].Attributes["account1.name"]

     

    I'm not sure why it added 1 to the account entity name but its there.  You can see this by doing entityResults.Entities[0].Attributes.ToList(); in the Immediate Window in Visual Studio.

    Thursday, October 27, 2011 5:51 PM
  • Did this resolve the problem?

    Please come back to post in your solution and mark the post answered to close the thread if you have no further questions related to this.

    Thanks!

    Sam


    Web: http://www.inogic.com
    Blog: http://inogic.blogspot.com
    Email: news@inogic.com
    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    Friday, October 28, 2011 6:40 AM
  • After Implementing alias.attribute i got this error

    :(

    exception: error 0x17EO.
    at ServiceReference.Entity.GetAttributeValue[T](String attributeLogicalName)
    at MainPage.AccountList_ClickCallback(IAsyncResult result)

     

    Problem is still there.

     

     

    Thanks for the reply.

    Friday, October 28, 2011 11:37 AM
  • Miley you are right this is not working

    After Implementing alias.attribute i got this error

    :(

    exception: error 0x17EO.
    at ServiceReference.Entity.GetAttributeValue[T](String attributeLogicalName)
    at MainPage.AccountList_ClickCallback(IAsyncResult result)

     

    Problem is still there.

     

     

    Thanks for the reply.

    Friday, October 28, 2011 11:39 AM
  • Actually, it works for me using the following line of code:

     

    string value = (string)entity.Attributes["alias.attribute"];

     


    Infusion | xrm2011.wordpress.com | @fantocci

    Friday, October 28, 2011 1:56 PM
  • I am glad this worked for you.  I will have to make a note of this one.  I think the items I think I have run into that doesn't work is trying to sort based on an aliased attribute.
    Jamie Miley
    Check out my about.me profile!
    http://mileyja.blogspot.com
    Linked-In Profile
    Follow Me on Twitter!
    Tuesday, December 27, 2011 3:35 PM
  • Hi Jamie,

    Were you able to sort based on linked entity field ? If yes please let me know... I'm also struggling to sort the record set based on the linked entity field. 

    Thanks

    Tuesday, May 08, 2012 1:40 AM
  • I was not able to sort by the linked attribute field.

    Jamie Miley
    Check out my about.me profile!
    http://mileyja.blogspot.com
    Linked-In Profile
    Follow Me on Twitter!

    Wednesday, May 09, 2012 3:17 PM
  • Hello Jamie,

    Thanks for replying. 

    Indika

    Tuesday, May 15, 2012 4:28 AM
  • Hi,

    Since you given link entity 'alias' as "a_a5eac3556ee4e011bfce782bcb1b2b74".

    Try this 

    if(entity["a_a5eac3556ee4e011bfce782bcb1b2b74.address1_city"] is AliasedValue){

    string address = (entity["a_a5eac3556ee4e011bfce782bcb1b2b74.address1_city"as AliasedValue).Value.ToString();

    }

    Thanks,
    Rajeev

    Tuesday, October 23, 2012 3:06 PM