Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Gabe Alam 6 posts 96 karma points
    May 24, 2019 @ 17:37
    Gabe Alam
    0

    ContentService GetPagedDescendants no results

    Umbraco 8

    I'm trying to get all nodes of a certain type - regardless of publish state (hence why I'm using ContentService). I figured I'd get all nodes and filter from there.

    From the code as well as other forum threads it seems like I want ContentService.GetPagedDescendants() - but I'm running into an issue where it returns 0 elements. Even more curiously, the out totalRecords does return the proper number.

    Here's my content structure:

    And the code:

    As you can see, descendants has 0 elements but returnCount is 3 (as is expected).

  • Bryna 73 posts 259 karma points
    May 24, 2019 @ 19:43
    Bryna
    0

    I am also getting this, even when I pass in -1 for the rootNode.Id. I am able to do below:

    IEnumerable<IContent> z =  contentService.GetPagedDescendants(-1, 1, 1000, out totalStale).Where(x => x.Published).AsEnumerable<IContent>()
    

    But 0 results are returned. How 0dd. Does it work for you when you move the code into a Razor View and Use IPublishedContent instead? Depending on what you are trying to accomplish, this might be a viable alternative.

  • Gabe Alam 6 posts 96 karma points
    May 24, 2019 @ 19:46
    Gabe Alam
    0

    I haven't tried anything with IPublishedContent as I need all IContent, not just published elements. This is being used in an on save handler so there's no view for it.

  • Thomas 315 posts 602 karma points c-trib
    Jul 05, 2019 @ 15:19
    Thomas
    3

    Change our "pageIndex" to 0. instead or 1.

    Had the same problem, but @Martijn helped me with this :) !

    This is what I have:

    IEnumerable<IContent> Children = Services.ContentService.GetPagedDescendants(pageId, 0, 5, out long TotalChildren, null, Ordering.By("date", Direction.Ascending, null, true));
    
  • Tim Miller 32 posts 252 karma points
    Sep 19, 2019 @ 17:11
    Tim Miller
    1

    I glossed right over this the first time or two. Changing the pageIndex to 0 is what fixed the issue for me too. I'm not sure why a zero index was confusing here, but it was. Unfortunately, I had to find that myself since I skipped right over this as the answer. Just trying to reinforce this as the answer since it wasn't marked as such.

Please Sign in or register to post replies

Write your reply to:

Draft