Copied to clipboard

Flag this post as spam?

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


  • Nathan Woulfe 447 posts 1664 karma points MVP 5x hq c-trib
    Jan 25, 2017 @ 06:13
    Nathan Woulfe
    0

    Sort order overwritten on save?

    I'm programmatically creating a node, setting a sort order value to make it the first, rather than last child of its parent. Saving the node then over-writes the set order:

    // ... create newNode, set some properties
    
    // get the children of the parent, sort by sort order
    // get the first (ie lowest sortOrder), subtract 1 to put the new node first
    var parent = contentService.getById(id);
    var sortOrder = parent.Children().OrderBy(c => c.SortOrder).First().SortOrder - 1;
    
    // set the newNode sort order
    newNode.SortOrder = sortOrder;
    
    contentService.Save(newNode);
    // newNode.SortOrder = parent.Children().OrderBy(c => c.SortOrder).Last().SortOrder + 1;
    

    Why would this be happening?

  • Dave Woestenborghs 3504 posts 12134 karma points MVP 9x admin c-trib
    Jan 25, 2017 @ 07:08
    Dave Woestenborghs
    0

    Hi Nathan,

    Maybe this sets the sort order to -1 and maybe that can't be saved :

    parent.Children().OrderBy(c => c.SortOrder).First().SortOrder - 1;
    

    Can you check if it's negative value ?

    Dave

  • Nathan Woulfe 447 posts 1664 karma points MVP 5x hq c-trib
    Jan 25, 2017 @ 07:17
    Nathan Woulfe
    0

    Thought that might be it, but nah - I'm refactoring a bit of code which previously looped through all the children, incremented the sortorder, saved and published each node, which was slow.

    Given that has run plenty of times previously, the lowest sort order value is pretty high, so no negative.

    The new node is unsaved when I set the value, might try fetching the new sort order value, saving the new node, setting the sort order and resaving. Would still be way more efficient than republishing a dozen nodes.

  • Nathan Woulfe 447 posts 1664 karma points MVP 5x hq c-trib
    Jan 31, 2017 @ 22:57
    Nathan Woulfe
    100

    Saving the new node, setting the sort order, then saving again resolved this one.

Please Sign in or register to post replies

Write your reply to:

Draft