No children found when using IContentRepository GetChildren on a scheduled task (EPiserver CMS 8.11)


My Solution is running on latest version of EPiserver CMS 8, multi-language environment.

GetChildren works nicely on my webpages as expected, but when I try to run GetChildren within scheduled task it was not loading any child on my test environment.

After testing a lot I found that if the page is not translated to the master-language it is not loaded in the scheduled task context with GetChildren. Maybe a bug?

I needed to get the page also if it is not translated. My solution was to add the CultureInfo.InvariantCulture to the getchildren function and filter out everything else than the published sites.

If any have a better solution please add a note.

Example code

var parentPage = ...;
            var pageList = _contentRepository.GetChildren(parentPage, CultureInfo.InvariantCulture);

            return workRooms.Where(x => x.CheckPublishedStatus(PagePublishedStatus.Published));
Mar 11, 2016 8:41

Correct examplecode:

var parentPage = ...;
var pageList = _contentRepository.GetChildren<mypagetype>(parentPage, CultureInfo.InvariantCulture);

return pageList.Where(x => x.CheckPublishedStatus(PagePublishedStatus.Published));

Mar 11, 2016 8:49

Yup adding culture can be necessary on scheduled job sometimes. Also remember that if you run it automatically you are fetching pages as anonymous user by default. So running a job manually usually works but automatically fails because of that reason...

Mar 11, 2016 9:12
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.