Fetch persons with specific template


What is the best way to fetch all persons with a specific template in the solution?

Litium version: 7.2

You need to use DataService, you need to store the result in cache if public page.

do you have any example for that? I was thinking something like this: query.Filter(f => f.Field("someId", "eq", fieldTemplateId)) but since the template isn’t a field this will not work.

I also found this:

using (var db = _dataService.CreateQuery<Page>())
       return db.Filter(f => f
                .TemplateSystemId("eq", fieldTemplate.SystemId))

But the extension TemplateSystemId() doesn’t exist for Person entity. Is this even possible? Or should I fetch all the customers and then filter the result?

You are interested to get all <Person> objects. and FieldTemplateSystemId exists in Person entity see:

Seems like no filtering for templates on Person is built in for the moment.
So other choice is to fetch all Persons and filter afterward which can have negative effect on performance if there are a lot of customers or other option could be pre-index the FieldTemplateSystemId and get them with Search API but the downside could be that search-index might not always be 100% updated at the time you are doing the search request.

Ok, I understand, this will be a scheduled task that will run once a week so I think it will be fine.

We solve the problem by adding a field for the TemplateId and populating the field programmatically (through integration and by subscribing on the PersonCreated event) to avoid more work for admin. In this way we also avoid possible performance issues since there is no filtering for templateSystemId for persons.

Thanks @steve.redstorm and @patric.forsgard for your suggestions!


This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.