Firstly, here's your query:
<fetch mapping='logical'>
<entity name='listmember'>
<link-entity name='list' from='listid' to='listid'>
<attribute name='listname'/>
</link-entity>
<link-entity name='contact' from='contactid' to='entityid'>
<attribute name='fullname'/>
<attribute name='emailaddress1'/>
</link-entity>
</entity>
</fetch>
Example results:
<resultset morerecords='0' paging-cookie='<cookie page="1"><listmemberid last="{E1B03485-0000-0000-0000-00155D107003}" first="{A74C877A-0000-0000-0000-00155D107003}" /></cookie>'>
<result>
<listmemberid>{A74C877A-0000-0000-0000-00155D107003}</listmemberid>
<listid.listname>List 1</listid.listname>
<entityid.fullname>Amy Pickle</entityid.fullname>
<entityid.emailaddress1>apickle@domain.com</entityid.emailaddress1>
</result>
<result>
<listmemberid>{A94C877A-0000-0000-0000-00155D107003}</listmemberid>
<listid.listname>List 2</listid.listname>
<entityid.fullname>Andrew Colley</entityid.fullname>
<entityid.emailaddress1>colley@domain.com</entityid.emailaddress1>
</result>
</resultset>
Not sure how well I can describe this in general terms but:
- You're looking for members of lists so
listmember
must be the root entity you return
- For each relationship to that entity that contains attributes you want to display, you need to define a
link-entity
(in this case, one to list
to get the list name and another to contact
to get contact's details
- you want to only display certain
attribute
s, so they each need to be defined within your link-entity
- you didn't specify any filtering so all memberships of all lists that are contacts will be returned
I never do these by hand. Previously I used James Downey's FetchXML Builder but I believe this is no longer available - Stunnware do a similar tool.