Retrieve Multiple distinct records RRS feed

  • Question

  • Hi all,

    I have a custom entity named School. In the School, there's an attribute called Suburb. School might be in the same Suburb with other School. Example:

    Name: School A | Suburb: Alexandria Suburb
    Name: School B | Suburb: Alexandria Suburb
    Name: School C | Suburb: Berkerley Suburb
    Name: School D | Suburb: Berkerley Suburb
    Name: School E | Suburb: Darlington Suburb

    Can I retrieve the distinct suburb data from School entity? If I retrieve the School data then I will get a double data for Suburb Alexandria (from above example).

    I'm not sure what kind of FilterExpression should I use. Thanks for any help!! :)

    Regards, Astri Kusumawardani
    Sunday, January 31, 2010 7:51 AM


All replies

  • If you use RetrieveMultiple or Fetch - key field is always returned in response. So distinct directive would not help you. So you have to add own logic to handle duplicated Suburb  fields.

    Truth is opened the prepared mind

    My blog (english)
    Мой блог (русскоязычный) free counters Locations of visitors to this page
    Sunday, January 31, 2010 8:02 AM
  • so you mean, after i do the RetrieveMultiple, i add my own logic to process the result data of RetrieveMultiple? Hm.. that will take twice a process.. 
    1. do a RetrieveMultiple
    2. handle the duplicated suburb

    is there any alternative to this? thanks.

    Regards, Astri Kusumawardani
    Monday, February 1, 2010 1:04 AM
  • You could try using a Fetch with the Distinct attribute set, rather than RetrieveMultiple, and just return the Suburb attribute  
    Microsoft CRM MVP - http://mscrmuk.blogspot.com  http://www.excitation.co.uk
    Monday, February 1, 2010 6:11 AM
  • No luck.

    I'm using below string to fetch the suburb only. Still receives the duplicated suburb data


    string fetchSuburb = @"

    <fetch mapping='logical'>

      <entity name='school'>

        <attribute name='suburb' distinct='true'/>




    Regards, Astri Kusumawardani
    Monday, February 1, 2010 12:00 PM
  • The distinct attribute should be on the Fetch element. Try:

    string fetchSuburb = @" ;

    <fetch mapping='logical' distinct='true'>

      <entity name='school'>

        <attribute name='suburb' />




    Microsoft CRM MVP - http://mscrmuk.blogspot.com  http://www.excitation.co.uk
    Monday, February 1, 2010 6:47 PM
  • Awesome! It works :D
    Thanks a bunch, David! You've helped me.
    Regards, Astri Kusumawardani
    Tuesday, February 2, 2010 3:10 AM