We are trying to get contacts from a segmented list for a custom auto-enroll feature.
When using built-in Sitecore conditions for segmented lists, like surname etc, this works fine. However, we are using custom conditions in our rules, and they appear to be breaking how we pull contacts programmatically. While the Sitecore ListManager is showing 22 contacts for the condition I'm using, my code shows 6682.
First, it's important to state that our data structure is different than the default contact structure built into xDb. Our contacts can have one or many "Opportunity" child objects, which also possibly contain child objects. We have custom facets that help us define this data.
Second, we are using Azure Search, and because it doesn't handle indexing complex objects, we've had to index arrays of values for our child objects.
Third, we are using some custom conditions that require us to query on more than one field, and in the particular case I'm testing right now, the condition makes use of a Treelist of custom settings items to choose a value for one of the fields.
So, the resulting Segmented List has a query that looks like this:
Notice that the Field1 value is a Guid.
The ListManager in Sitecore returns 22 contacts for this segmented list.
We noticed that Sitecore makes a call to /sitecore/api/ssc/ListManagement/Contacts to pull these contacts.
We used DotPeek to take a look at the ContactsController in Sitecore.ListManagement.Services, and noticed that the default action looks broken, so we're not sure how it's returning anything, let alone the correct contacts.
We created a pdb of Sitecore.ListManagement.Services and were able to debug this method in VS. It is indeed being called when we load the segmented list using the ListManager in Sitecore, so we believe we're looking in the right place.
This line appears to pull the contacts: IQueryable source = this.contactFilter.ApplyFilterExpression(this.listManager.GetContacts(this.listManager.FindById(listId)), filter == null ? (string) null : filter.Trim());
When we create a new instance of ListManager in our code, then call listManager.GetContacts and pass in the list object, We get 6682 contacts returned, instead of the 22 that the Sitecore ListManager returns.
Given that we're using the same ListManager call that the ContactsController is using, we're not sure why we're getting such a drastically different number of contacts returned.
Let me know if we need to post some code samples.