0

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.

Any ideas?

Let me know if we need to post some code samples.

Thanks!

  • Just realized the title has a spelling mistake... Oops! I do know how to spell Segmented :) – PTCDrummer Jul 5 at 22:54
  • How will you be using this? As a note, ListManagement is not available through the CD roles. – Pete Navarra Jul 8 at 12:17
  • Thanks for getting back. We will solely be using this on the CM role. We have a role-specific task that runs some code to read from segmented lists and get the contacts that result from the segmentation rules. I see that the Sitecore.ListManagement.Services.ContactsController returns the correct number of contacts when fed the list id. (We navigate to it using: /sitecore/api/ssc/ListManagement/Contacts?pageSize=25&pageIndex=0&payLoad=full&language=en&listId=[list id]&filter=&sc_lang=en.) – PTCDrummer Jul 8 at 17:24
  • We are using the same ListManager.GetContacts(list) code in our custom solution, but when we feed our code the same list id, we get 6682 contacts. I'm wondering if we are missing some context that the ContactsController is accepting. I placed some breakpoints in the various constructors in the controller, but the only one that gets hit is the one with the ListManager and ContactFilter objects passed in, Most of the variables I hover over are optimized, so I'm not able to see if there's anything special about those passed-in objects. – PTCDrummer Jul 8 at 17:24
  • Update - I believe I have found and solved our issue. Our custom conditions that pulled a value from a treelist were written to use Sitecore.Context.Database, which when run in the ListManager were fine, but from our back-end code Sitecore.Context.Database was null. I have changed how we're getting the context database, so it appears we're good. – PTCDrummer Jul 9 at 17:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.